wkhtmltopdf

Java 通过wkhtmltopdf在线生成PDF

佐手、 提交于 2020-04-22 02:28:05
1. 下载安装wkhtmltopdf; 百度网盘: https://pan.baidu.com/s/1Lb28f93nY0N86iW0MhFA9g 提取码:s2fa 2. 创建一个工具类WKHtmlToPdfUtilUtil.java,写入以下代码: package com.zghky.utils; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.Date; public class WKHtmlToPdfUtil { private static class ClearBufferThread implements Runnable { private InputStream in; public ClearBufferThread(InputStream inputStream) { this.in = inputStream; } @Override public void run() {

Python之将Python字符串生成PDF

不羁岁月 提交于 2020-04-18 00:23:19
  笔者在今天的工作中,遇到了一个需求,那就是如何将Python字符串生成PDF。比如,需要把Python字符串‘这是测试文件’生成为PDF, 该PDF中含有文字‘这是测试文件’。   经过一番检索,笔者决定采用wkhtmltopdf这个软件,它可以将HTML转化为PDF。wkhtmltopdf的访问网址为: https://wkhtmltopdf.org/downloads.html ,读者可根据自己的系统下载对应的文件并安装。安装好wkhtmltopdf,我们再安装这个软件的Python第三方模块——pdfkit,安装方式如下: pip install pdfkit   我们再讨论如下问题: 如何将Python字符串生成PDF; 如何生成PDF中的表格; 解决PDF生成速度慢的问题。 如何将Python字符串生成PDF   该问题的解决思路还是利用将Python字符串嵌入到HTML代码中解决,注意换行需要用 <br> 标签,示例代码如下: import pdfkit # PDF中包含的文字 content = '这是一个测试文件。' + '<br>' + 'Hello from Python!' html = '<html><head><meta charset="UTF-8"></head>' \ '<body><div align="center"><p>%s</p><

FileNotFoundError: [Errno 2] No such file or directory: 'which' when using python pdfkit

有些话、适合烂在心里 提交于 2020-04-14 06:07:09
问题 I have a strange error. I try to use pdfkit to convert an HTML string to PDF, but i get a "No such file or directory: 'which'". I know that pdfkit uses wkhtmltopdf, and it tries to find this utility by using which. I have no idea what's happening. 'which' works ok and wkhtmltopdf is installed on /usr/bin/. I get the error in this line: pdf = pdfkit.from_string(html, False, options=options) and the traceback: Traceback: File "/srv/zboss-git/venv/lib/python3.5/site-packages/django/core/handlers

PHP输出PDF打印HTML5+CSS3打印格式控制

浪子不回头ぞ 提交于 2020-03-27 18:23:39
3 月,跳不动了?>>> ERP系统进入尾声,各种送货单、退货单、合同、对账单等等一系列的东东排着队调打印格式。HTML5+CSS3已经这样流行,然则眼下,基于CSS3的打印控制,居然还处于原始部落阶段,Chrome、Firefox、Edge等连简单的@page都支持得不完善。经过一番折腾,终于找到好的解决方案,即借道输出PDF,先让PHP抓取目标的HTML代码,然后输出到指定解析器,生成PDF内容,最终打印。 实际上,这个模式里: 1. HTML5+CSS3,只是输出内容的调节环节,需要确保CSS3 @page的全特性支持无误。尤其是长文章(合同)分页,和长表格自动分页(最好是thead和tfoot能分页重复显示)。 2. PDF预览时,实际上就是打印前的排版预览,之后就直接输出打印即可。 3. PDF可供用户自行下载成本地文件做备份。 4. HTML内容(PDF内容),可以通过缓存类库进行缓存,自己调控周期、压缩存储即可。 于是打印问题迎刃而解。 本文推荐两个可用的类库: Prince 和 wkhtmltopdf 。这两位都是跨平台系统支持,并且不需要内嵌于php,不需要有任何担心。 这两货都需要在官网下载安装,如果是windows,记得安装的时候别放在C盘,不然会无法执行。 php调用: Prince:下载他官方的这个类库: Prince for php 。顺带说

“Could not connect to display” on EC2 Server

≡放荡痞女 提交于 2020-03-22 06:54:24
问题 I'm trying to export some pandas dataframe tables as images. I looked at many solutions, and found what seemed like the best bet. I followed the directions on this site, and everything worked fine locally. However, when trying to get this python script to run on an EC2 server, I get the following error: OSError: wkhtmltoimage exited with non-zero code 1. error: qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display. You need to install xvfb(sudo apt-get

How do I get total pages in wkhtmltopdf body?

我只是一个虾纸丫 提交于 2020-03-01 01:45:21
问题 Is it possible to access the "topage" variable within the main content body? I know you can do it in headers and footers but in this specific use case, I need to put a sentence within the body that says: "This document contains XX pages". 回答1: This works to me. But need to be in the header (ou footer) In the body I think it is not possible, like they said in the GitHub http://github.com/wkhtmltopdf/wkhtmltopdf/issues/1889 To put this info in the footer you can see @Unixmonkey in this link:

在.NET中将HTML转换为PDF

雨燕双飞 提交于 2020-02-26 11:45:57
我想通过将HTML内容传递给函数来生成PDF。 我已经为此使用了iTextSharp,但是当它遇到表格并且布局变得凌乱时,它的表现不佳。 有没有更好的办法? #1楼 尝试使用此 PDF Duo .Net 转换组件,可将 HTML从ASP.NET 应用程序转换 为PDF, 而无需使用其他dll。 您可以传递HTML字符串或文件,或流以生成PDF。 使用下面的代码(示例C#): string file_html = @"K:\hdoc.html"; string file_pdf = @"K:\new.pdf"; try { DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf(); conv.OpenHTML(file_html); conv.SavePDF(file_pdf); textBox4.Text = "C# Example: Converting succeeded"; } 您可以在以下位置找到Info + C#/ VB示例: http : //www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx #2楼 好的,使用这项技术。 飞碟项目 IKVM 存根 o src可以从 这里 下载,需要 nant #3楼 更新: 现在我推荐在

Run wkhtmltopdf on CentOS 5.5 32bit

对着背影说爱祢 提交于 2020-02-06 15:45:08
问题 I'm trying to run wkhtmltopdf on CentOS 5.5 32bit version, I'm running that software on a VPS. Somehow I cannot execute the binary, this is what I get: -bash-3.2# ./wkhtmltopdf-i386 http://www.google.nl/ test.pdf Segmentation fault I haven't got a clue to what the problem might be, the file has the proper owner and it's permissions are 777. The only thing I can think of making this problem go away is installing the X11 packages on my VPS, I'm not sure if that will solve the problem though.

text-align: justify; not working with wkhtmltopdf

南楼画角 提交于 2020-02-03 08:55:27
问题 Good day! I'm creates PDF docs from HTML using wkhtmltopdf library. I used svg font according to this issue wkhtmltopdf custom font letter spacing I used custom font, added it by @font-face. All works fine for me, except one thing: text-align: justify is not working for some reason. In html text is aligned as expected, but not in PDF. Is anyone know how to fix this issue? UPD : Added CSS and HTML example <style type="text/css"> @font-face{ font-family:'source_sans_prolight'; src: url('/font

Django wkhtmltopdf don't reading static files

我是研究僧i 提交于 2020-02-02 11:48:08
问题 I use wkhtmltopdf with django-wkhtmltopdf and I think I have incorrectly serving static files. If I run wkhtmltopdf from the console are properly collected static files and generates a good pdf file: wkhtmltopdf http://127.0.0.1:8000/dash/test/ test.pdf "GET /static/base/js/jquery.js HTTP/1.1" 200 93106 "GET /static/base/css/bootstrap.css HTTP/1.1" 200 119892 "GET /static/base/js/bootstrap.min.js HTTP/1.1" 200 27726 "GET /static/dash/css/flot.css HTTP/1.1" 200 1810 "GET /static/dash/js/jquery