1

我正在尝试用 Python 制作 PDF 文件,但我发现的所有工具都只能在 Python 2.7(或更低版本)上使用,而且我使用的是 3.2。我有一个可以在 3.2 上运行并生成 PDF 文件的工具或东西吗?或者让 2.7(或更低)代码在 3.2 上运行的方法?

4

1 回答 1

1

Not personally tested with Python 3.x, but official page says weasyprint works with it. It allows for HTML to PDF conversion, so depending on your needs and the rest of the project this may be an advantage or disadvantage.

For a low-level "draw the PDF yourself" you might want to try cairo, but looks like the automatic installation is a bit incomplete: Cairo example works with Python 2.7 but does not work in Python 3

To convert python 2.x code to python 3.x code you may use the following two tools:

  1. 2to3
  2. Your brain

The latter tool are much more powerful, and sort of guarantees successful conversion, but a little bit slow compared to the former.

于 2013-06-20T18:25:42.117 回答