QT生成PDF

news/2025/1/15 14:51:57/

使用第三方工具wkhtmltopdf

//p:自定义html缓存和PDF保存文件夹;content:html;name:pdf文件名称bool BuildPDF(QString& p,QString content,QString name)//生成pdf{QString softpath = QApplication::applicationDirPath() + "/wkhtmltopdf/wkhtmltopdf.exe";QString filePath = QString("\"").append(p).append("/").append(name).append(".pdf\"");QString htmlpath = p + QString("/").append("DEMO").append(".html");//临时文件p.append("/").append(name).append(".pdf");QFileInfo qfi(softpath);if (!qfi.isFile()){return false;}QFile fi(htmlpath);if (!fi.open(QFile::WriteOnly | QIODevice::Truncate)){return false;}fi.write(content.toLocal8Bit());//html数据fi.close();QString path = QString("\"") + softpath + QString("\" \"") + htmlpath + QString("\" ") + filePath;int ret = QProcess::execute(path);if (ret < 0){FXC << "failed : " << filePath << ret;return false;}return true;}

下面是content:

<!DOCTYPE html>
<html><head><meta lang="zh-cn"><meta charset="UTF-8"><style>/* 创建通用样式类 */.div-pandel {width: 100%;margin-top: 32px;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.title-large {/* width: 618px;height: 52px; */font-size: 24px;font-weight: normal;font-stretch: normal;margin-left: 45px;line-height: 44px;letter-spacing: 0px;margin-top: 90px;color: #000000;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.divier-full {size: 1px;color: #eaeaea;margin-top: 22px;margin-left: 45px;margin-right: 45px;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}/* 二级标题 */.title-info {font-size: 26px;font-weight: normal;font-stretch: normal;line-height: 44px;letter-spacing: 0px;color: #000000;margin-top:10px;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.label-title {height: 36px;font-size: 20px;font-weight: normal;font-stretch: normal;line-height: 44px;letter-spacing: 0px;color: #999999;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.label-title-ED5931 {height: 36px;font-size: 20px;font-weight: normal;font-stretch: normal;line-height: 44px;letter-spacing: 0px;color: #FFFFFF;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.lable-value {font-size: 20px;height: 36px;font-weight: normal;letter-spacing: 0px;color: #000000;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.label-layout-full {width: 100%;margin-top: 10px;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.label-layout {float: left;width: 50%;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}.table-layout {width: 100%;font-family:"MicroSoft YaHei", Gulim, "Malgun Gothic", sans-serif;}/*表格行*/.table-tr-ED5931 {width: 100%;height: 44px;word-wrap: break-word;word-break: break-all;overflow: hidden;background-color: #ED5931;}.table-tr-f6 {width: 100%;height: 44px;word-wrap: break-word;word-break: break-all;overflow: hidden;background-color: #f6f6f6;}.table-tr-ff {width: 100%;height: 44px;word-wrap: break-word;word-break: break-all;overflow: hidden;background-color: #FFFFFF;}.table-tr {width: 100%;height: 118px;word-wrap: break-word;word-break: break-all;overflow: hidden;background-color: #FFFFFF;}.table-td {height: 44px;font-size: 16px;font-weight: normal;font-stretch: normal;line-height: 44px;letter-spacing: 0px; word-wrap: break-word;word-break: break-all;overflow: hidden;color: #000000;}</style></head><body><h1 style="text-align:center;font-family:MicroSoft YaHei, Gulim, Malgun Gothic"><img src="E:/Software/Debug/company.png"style="float:right;width:283px;height:49;" />Vehicle Diagnostic Report</h1><hr /><div class="div-pandel"><div><span class="title-info">Vehicle Information</span></div><table class="table-layout"><tr class="table-tr-ff"><td width=33%class="table-td"><span class="label-title">Brand : </span><span class="lable-value">DEMO</span></td><td width=33%class="table-td"><span class="label-title">VIN : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Plate Number : </span><span class="lable-value"></span></td></tr><tr class="table-tr-ff"><td width=33%class="table-td"><span class="label-title">Model : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Mileage : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Color : </span><span class="lable-value"></span></td></tr><tr class="table-tr-ff"><td width=33%class="table-td"><span class="label-title">Year : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Capacity : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Status : </span><span class="lable-value">Unset status</span></td></tr><tr class="table-tr-ff"><td width=33%class="table-td"><span class="label-title">Engine : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Reference Number : </span><span class="lable-value"></span></td><td width=33%class="table-td"><span class="label-title">Date : </span><span class="lable-value">2023-04-28</span></td></tr></table></div><hr /><div class="div-pandel"><div><span class="title-info"style="font-size:30px; color:red;">故障码</span></div><table class="table-layout"><tr style="Background:#A0A0A0;"><td width=27%class="table-td">ID</td><td width=20%class="table-td">Status</td><td width=53%class="table-td">Description</td></tr><tr class="table-tr-ff"><td width=27%class="table-td">P0030</td><td width=20%class="table-td">激活</td><td width=53%class="table-td">HO2S加热器控制电路1排传感器1</td></tr><tr class="table-tr-f6"><td width=27%class="table-td">P2096</td><td width=20%class="table-td">历史</td><td width=53%class="table-td">催化转化器燃油修正过稀(1排)</td></tr><tr class="table-tr-ff"><td width=27%class="table-td">P0130</td><td width=20%class="table-td">激活</td><td width=53%class="table-td">O2传感器电路1排传感器1</td></tr><tr class="table-tr-f6"><td width=27%class="table-td">P0616</td><td width=20%class="table-td">历史</td><td width=53%class="table-td">起动机继电器电路电压低</td></tr><tr class="table-tr-ff"><td width=27%class="table-td">P0335</td><td width=20%class="table-td">激活</td><td width=53%class="table-td">曲轴位置传感器 ’A’ 电路</td></tr></table></div><div><div style="background:#ED5931;text-align:center;"><span class="title-info">Contact Information</span></div><table class="table-layout"><tr class="table-tr-ff"><td span=2class="table-td"><span class="label-title">Name : </span><span class="lable-value"></span></td></tr><tr class="table-tr-ff"><td span=2class="table-td"><span class="label-title">Address : </span><span class="lable-value">00.12</span></td></tr><tr class="table-tr-ff"><td width=50%class="table-td"><span class="label-title">Telephone : </span><span class="lable-value">123456</span></td><td width=50%class="table-td"><span class="label-title">Email : </span><span class="lable-value">dadf@dd.lc</span></td></tr><tr class="table-tr-ff"><td span=2class="table-td"><span class="label-title">Website : </span><span class="lable-value">www.fxowel</span></td></tr></table></div><hr /><div style="background:#F0F0F0;font-size:20px;text-align:center;color:#333333;font-family:MicroSoft YaHei, Gulim, Malgun Gothic">Software Version:V9.15.016</div></body>
</html>

http://www.ppmy.cn/news/162010.html

相关文章

C++ QT 读写TXT文件基操

读取txt文件&#xff1a; #include <QFile> #include <QTextStream> QFile file("filename.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream in(&file); while (!in.atEnd()) { QS…

硬件学习网站

1.资源搜索 google x度就是辣鸡 2.Hackday https://hackaday.io/projects 一天刷几十遍的开源硬件项目网站 3.Github https://github.com/ 也不全是软件&#xff0c;FPGA的开源矿机了解下 4.CircuitMaker https://workspace.circuitmaker.com 硬件版githubaltium 5.电路城 htt…

【复杂网络建模】——python通过平均度和随机概率构建ER网络

目录 一、复杂网络建模 二、ER网络 三、构建ER网络方法 四、基于python构建ER网络 1、基于节点数量和链接概率 2、基于平均度来生成 五、ER网络在现实中的实际应用 一、复杂网络建模 复杂网络建模是指对复杂网络进行描述和分析的过程。复杂网络是由大量相互连接的节点…

电脑、数码资讯网站

界面应设计得尽量洗练一些。与网页设计员直接有关的网页代理或网页设计员网站需要从美 的角度和技术的层面来表现出较高的水准。所以洗练的感觉和富有创意的表现手法是非常重要的。 http://www.unleashedmedia.com... 数码资讯、网页设计&#xff1a;由于是直接与网页设计者有…

国内 IT 相关网站

在网上搜了一些国内 IT 相关资讯的网站&#xff0c;按Alexa 上的国内排名排序。 中关村在线&#xff1a;http://www.zol.com.cn/ (34) 天极网&#xff1a;http://www.yesky.com/ (36) 知乎&#xff1a;https://www.zhihu.com/ (37) csdn: http://www.csdn.net/ (67) 站长之家…

计算机行业必备网站

1、Github: 程序员神站&#xff0c;代码实现只有你想不到的&#xff0c;没有你找不到的。上面有各种开源库供学习使用&#xff0c;程序员心中的信仰&#xff01; 网址&#xff1a;Github 2、Google 点名表扬Google学术&#xff0c;非常权威&#xff0c;前沿科研技术&#xff0…

诚信缺失 中关村传统电脑卖场面临“崩盘”?(转载搜狐)

睿商在线 王卫东 中关村“繁荣”的景象背后&#xff0c;正在酝酿一场前所未有的危机&#xff0c;以诚信为本的商业信条已被越来越多的商家抛弃&#xff0c;取而代之的是以透支诚信为代价的欺诈经营&#xff0c;并已被演义得日渐熟练且自成体系。 <script languagejavascrip…

笔记本电脑相关网站集锦

笔记本电脑相关网站集锦 2005-01-23 14:54:31 期号&#xff1a;2004年12月刊 笔记本电脑已经越来越普及&#xff0c;但每当身边的朋友准备选购笔记本电脑时&#xff0c;他们总有问不完的问题。对于大部分购买笔记本电脑的用户来说&#xff0c;一般都有一定程度的桌面电脑使用…