1、将html文件转为pdf文件的函数:

html_path-----html路径;pdf_path-----pdf路径 bool HtmlToPdf(QString html_path, QString pdf_path) { QFile::remove(pdf_path); int result = 0; wkhtmltopdf_global_settings * gs; wkhtmltopdf_object_settings * os; wkhtmltopdf_converter * c; /* Init wkhtmltopdf in graphics less mode */ wkhtmltopdf_init(false); /* * Create a global settings object used to store options that are not * related to input objects, note that control of this object is parsed to * the converter later, which is then responsible for freeing it */ gs = wkhtmltopdf_create_global_settings(); myassert(wkhtmltopdf_set_global_setting(gs, "collate", "true")); myassert(wkhtmltopdf_set_global_setting(gs, "outline", "true")); myassert(wkhtmltopdf_set_global_setting(gs, "margin.top", "2cm")); myassert(wkhtmltopdf_set_global_setting(gs, "out", pdf_path.toUtf8().data())); myassert( wkhtmltopdf_set_global_setting(gs, "load.cookieJar", "myjar.jar")); /* * Create a input object settings object that is used to store settings * related to a input object, note again that control of this object is parsed to * the converter later, which is then responsible for freeing it */ os = wkhtmltopdf_create_object_settings(); /* We want to convert to convert the qstring documentation page */ myassert(wkhtmltopdf_set_object_setting(os, "page", html_path.toUtf8().data())); myassert(wkhtmltopdf_set_object_setting(os, "toc.indentation", "2em")); myassert(wkhtmltopdf_set_object_setting(os, "useExternalLinks", "true")); myassert(wkhtmltopdf_set_object_setting(os, "web.loadImages", "true")); myassert(wkhtmltopdf_set_object_setting(os, "web.background", "true")); myassert(wkhtmltopdf_set_object_setting(os, "web.defaultEncoding", "utf-8")); /* Create the actual converter object used to convert the pages */ c = wkhtmltopdf_create_converter(gs); /* Call the progress_changed function when progress changes */ wkhtmltopdf_set_progress_changed_callback(c, progress_changed); /* Call the phase _changed function when the phase changes */ wkhtmltopdf_set_phase_changed_callback(c, phase_changed); /* Call the error function when an error occurs */ wkhtmltopdf_set_error_callback(c, error); /* Call the warning function when a warning is issued */ wkhtmltopdf_set_warning_callback(c, warning); /* * Add the the settings object describing the qstring documentation page * to the list of pages to convert. Objects are converted in the order in which * they are added */ wkhtmltopdf_add_object(c, os, NULL); /* Perform the actual conversion */ myassert(wkhtmltopdf_convert(c)); /* Output possible http error code encountered */ errcode = wkhtmltopdf_http_error_code(c); printf("httpErrorCode: %d\n", errcode); //QMessageBox::critical(nullptr, QString::number(errcode), // QString("httpErrorCode: %1").arg(QString::number(errcode))); /* Destroy the converter object since we are done with it */ wkhtmltopdf_destroy_converter(c); /* We will no longer be needing wkhtmltopdf funcionality */ myassert(wkhtmltopdf_deinit()); return true; }

2、下图是html转dpf时出现的问题

这是修复好的pdf

3、解决方案

在对应的html文件里面添加如下:

table, tr, td, th, tbody, thead, tfoot {page-break-inside: avoid !important;}即可解决

激光扫描安全距离检测报告

html页面导出pdf截断问题,利用wkhtmltopdf(thead)将网页导出为pdf方法;以及存在表格图片被分页打断的问题解决方法...相关推荐

  1. Python编程:使用wkhtmltopdf将html网页转成pdf文件

    官网:https://wkhtmltopdf.org/ github: https://github.com/wkhtmltopdf/wkhtmltopdf Mac环境: brew install C ...

  2. 用c语言怎样将swf转化为pdf,利用ABCpdf.NET将网页转换成PDF的方法小结

    中转方式: 大多数时候,都是使用WebBrowser空间,将网页截图,然后插入PDF文件,另外也可以将网页先保存为Word文件,然后再从Word转PDF. PDF虚拟打印机: 还有一种方式,就是使用虚 ...

  3. 使用PDF.js实现前端和手机端网页预览PDF文件(可定制,支持本地文件、Base64编码和远程URL跨域方式)

    1.插件下载地址:https://mozilla.github.io/pdf.js/ 下载后解压pdfjs-1.10.88-dist.zip文件后得到: 2.把pdfjs-1.10.88-dist放到 ...

  4. java实现html页面转pdf解决方案_[Java教程]纯js实现html转pdf

    [Java教程]纯js实现html转pdf 0 2017-02-16 00:00:30 项目开发中遇到了一个变态需求,需要把一整个页面导出为pdf格式,而且要保留页面上的所有的表格.svg图片和样式. ...

  5. 利用Chrome Headless模式网页转PDF

    本文转载于:https://blog.csdn.net/aWDac/article/details/80865754       https://blog.csdn.net/xcl168/articl ...

  6. 怎样把网页保存为pdf?+如何删除pdf上面的某些东西

    文章目录 怎样把网页保存为pdf? 如何删除pdf上面的某些东西 怎样把网页保存为pdf? 牛逼之处在于他把滚动条下面所有内容都保存了 网页中右键单击,选中"打印" "打 ...

  7. 网页导出pdf不完整_网站中的页面如何转成PDF文档?

    在我们浏览网站时,需要保存网页以供日后离线浏览,或是想要分享或打印网页,那就可以考虑把网页转换成PDF文件来简化整个操作. 那么应该如何将网页转成PDF呢?网页上的信息如何保存成PDF,操作方法是什么 ...

  8. jspdf-html2canvas 自动分页 网页导出pdf 自动根据dom子节点的高度进行分页,避免dom的内容在分页的时候被截断

    jspdf-html2canvas 网页导出pdf 自动根据dom子节点的高度进行分页,避免dom的内容在分页的时候被截断 说明 直接上代码 说明 要导出的内容用 .pdf 包裹 ,默认会以.pdf的 ...

  9. 利用若依@Excel注解导出PDF工具类

    利用若依@Excel注解导出PDF工具类 1.pom依赖 <!--PDF导出--><dependency><groupId>com.itextpdf</gro ...

最新文章

  1. 英特尔第三代 Ice Lake 发布正面与 AMD EPYC PK,结果令人大跌眼镜!
  2. 一文详尽系列之逻辑回归
  3. UA MATH524 复变函数9 柯西公式与幂级数展开
  4. [IOI2008]Island
  5. @RequestParam与@PathVariable的区别
  6. oracle db-link 分布式数据库网络配置协议错误,Oracle学习(18)【DBA向】:分布式数据库...
  7. mysql 8.0.22_最新版MySQL 8.0.22下载安装超详细教程(Windows 64位)
  8. 哈希表(hashtable)的javascript简单实现
  9. 2021年互联网租房行业洞察报告
  10. VS返回到上次编辑和进入到下次编辑的位置快捷键
  11. 集成微信支付的代码。兼容小程序,扫码,app,公众号。h5 支付 ,以及 服务商提现...
  12. 导入JasperReports坐标时无法下载com.lowagie:itext:jar:2.1.7.js6
  13. windows本地破解用户口令
  14. SDL介绍----1、SDL与SDL安全活动
  15. 每个产品经理都应该了解的5大技术技能
  16. 未来教育安装后打不开
  17. 使用linux集体升级系统,1.3. 利用mtd工具升级Linux系统
  18. 2021年bilibili程序员节日
  19. 祭祀扫墓网站php源码,斗破苍穹:不可错过的玄幻
  20. 开关电源布局布线总结

热门文章

  1. 申请了一张招行的全币种信用卡
  2. ubuntu 安装软件 tar.gz deb
  3. 1381:城市路(Dijkstra)
  4. 线程实用解析--------(六)Control.Invoke()和Control.BeginInvoke()
  5. win7 64位 system32和syswow64文件夹
  6. 运维级医院PACS系统全套源代码
  7. WIN7 iTunes无法识别iPhone,重装系统解决
  8. github上传文件出错
  9. windows提权常用系统漏洞与对应的补丁编号
  10. 如何判断Android系统的版本