生成PDF的最简单方法是什么?

时间:2017-08-17 03:52:08

标签: pdf pdf-generation

我想生成带有特定输入的格式化PDF文档。

由于我必须制作大量相同类型的报告:格式相同,而内容则有所不同。什么是最好和最简单的方法?

我所知的语言:HTML,CSS,Python

2 个答案:

答案 0 :(得分:1)

如果您愿意学习一点Java(或.net),那么iText就是您的选择。

  • 广泛使用
  • 加载示例代码
  • iText开发团队定期检查StackOverflow是否与社区联系
  • 提供商业支持

查看http://developers.itextpdf.com/examples-itext7

你可以(理论上)使用Jython从Python运行Java: - )

小例子:

File outputFile = new File("hello_world.pdf");
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outputFile));
Document layoutDocument = new Document(pdfDocument);
layoutDocument.add(new Paragraph("Hello World!"));
layoutDocument.close();

iText还提供将CSS和HTML转换为pdf的工具。我认为这对你的情况来说是理想的。您只需编写一小段代码即可进行转换。然后,您可以从HTML创建报告。

要使用pdfHTML,以下代码应该足够了:

// IO
File htmlFile = new File("index.html");
File pdfFile = new File("index.pdf");

// actual conversion code
HtmlConverter.convertToPdf(new FileInputStream(htmlFile), new FileOutputStream(pdfFile));

答案 1 :(得分:0)

有很多选项可供使用,我建议您选择最适合的语言,只需谷歌“用x创建pdf”,其中x是语言。

python的类似问题:

How do I create a PDF file, including images and text, from Python?

How to create PDF files in Python

https://www.quora.com/What-is-the-best-way-to-create-pdf-files-with-Python

PyLaTeX也很不错: https://github.com/JelteF/PyLaTeX

相关问题