html页面导出pdf截断问题,利用wkhtmltopdf(thead)将网页导出为pdf方法;以及存在表格图片被分页打断的问题解决方法...
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方法;以及存在表格图片被分页打断的问题解决方法...相关推荐
- Python编程:使用wkhtmltopdf将html网页转成pdf文件
官网:https://wkhtmltopdf.org/ github: https://github.com/wkhtmltopdf/wkhtmltopdf Mac环境: brew install C ...
- 用c语言怎样将swf转化为pdf,利用ABCpdf.NET将网页转换成PDF的方法小结
中转方式: 大多数时候,都是使用WebBrowser空间,将网页截图,然后插入PDF文件,另外也可以将网页先保存为Word文件,然后再从Word转PDF. PDF虚拟打印机: 还有一种方式,就是使用虚 ...
- 使用PDF.js实现前端和手机端网页预览PDF文件(可定制,支持本地文件、Base64编码和远程URL跨域方式)
1.插件下载地址:https://mozilla.github.io/pdf.js/ 下载后解压pdfjs-1.10.88-dist.zip文件后得到: 2.把pdfjs-1.10.88-dist放到 ...
- java实现html页面转pdf解决方案_[Java教程]纯js实现html转pdf
[Java教程]纯js实现html转pdf 0 2017-02-16 00:00:30 项目开发中遇到了一个变态需求,需要把一整个页面导出为pdf格式,而且要保留页面上的所有的表格.svg图片和样式. ...
- 利用Chrome Headless模式网页转PDF
本文转载于:https://blog.csdn.net/aWDac/article/details/80865754 https://blog.csdn.net/xcl168/articl ...
- 怎样把网页保存为pdf?+如何删除pdf上面的某些东西
文章目录 怎样把网页保存为pdf? 如何删除pdf上面的某些东西 怎样把网页保存为pdf? 牛逼之处在于他把滚动条下面所有内容都保存了 网页中右键单击,选中"打印" "打 ...
- 网页导出pdf不完整_网站中的页面如何转成PDF文档?
在我们浏览网站时,需要保存网页以供日后离线浏览,或是想要分享或打印网页,那就可以考虑把网页转换成PDF文件来简化整个操作. 那么应该如何将网页转成PDF呢?网页上的信息如何保存成PDF,操作方法是什么 ...
- jspdf-html2canvas 自动分页 网页导出pdf 自动根据dom子节点的高度进行分页,避免dom的内容在分页的时候被截断
jspdf-html2canvas 网页导出pdf 自动根据dom子节点的高度进行分页,避免dom的内容在分页的时候被截断 说明 直接上代码 说明 要导出的内容用 .pdf 包裹 ,默认会以.pdf的 ...
- 利用若依@Excel注解导出PDF工具类
利用若依@Excel注解导出PDF工具类 1.pom依赖 <!--PDF导出--><dependency><groupId>com.itextpdf</gro ...
最新文章
- linux命令-mkdir命令
- SQL Server 2008如何进行数据库同步?
- 逆向与分析-WebBrowserPassView消息分析
- forward_list的insert操作
- SAP Spartacus的产品主数据模型
- 《简明 Python 教程》笔记
- phalcon: Profiling分析 profilter / Plugin结合,dispatcher调度控制器 监听sql执行日志
- error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
- 杭电HDUacm2037
- 【笔记】更改windows,excel,word背景色为眼睛保护色
- 【Cocos Creator】 编辑器自定义 ——下拉列表属性、滑动条属性等
- SpringBoot快速入门--基础版(包含整合常用框架、跨域)
- 苹果基带坏了怎么办_「手机维修自学教程」苹果手机的基带逻辑码片读取技巧 保资料搬板...
- IT培训班有用吗?IT培训包就业是真的吗?
- 二叉平衡树之二叉树搜索树【咱们一起手动模拟实现】
- 华为大搞5G光通信,火星人快步紧跟
- Golang bytes源码分析
- 南安一中八十年校庆征文 陈建春老师
- 计算机软件 大shen
- 衡水东方计算机学校校景,衡水东方计算机学校宿舍条件
热门文章
- 图解IFRS9 金融工具(7)减值损失披露
- 黑马手机卫士黑名单电话拦截 使用ITelephony.aidl和NeighboringCellInfo.aidl 自动拦截黑名单电话 附文件
- Understand 2.5使用指南(中文)
- 《Microsoft SQL Server入门教程》第02篇 SQL Server 下载与安装
- 注重移动端体验,新商云带你开启社交电商新时代
- 【Rust 日报】2022-10-16 全栈同构Web框架leptos
- 解决需求变更难题的8大方案
- 计算机体系结构:不同改进方案的性价比计算(1.4)
- Error in nextTick: “TypeError: Cannot read property ‘xxx‘ of undefined“
- C++读写txt文档