从python创建pdf

我想从Python应用程序生成PDF.
它们开始相对简单,但有些可能会变得更复杂(基本上就像文档一样,但后面会包含水印)

我以前曾在原始postscript中工作过,并提供了我可以生成正确的标题等文件并在文件的最后我想避免使用复杂的库,这可能不完全符合我的要求.有些似乎已经有了bitrot并且不再受支持(pypdf和pypdf2)特别是当我知道PDF / Postscript可以完全满足我的需求时. PDF内容确实不那么复杂.

我可以通过将适当的文本标题写入文件和我的postscript代码来生成EPS(Encapsulated postscript).但是检查PDF有一个lil二进制头我不知道如何生成.

我可以生成EPS并转换它.我对此并不十分满意,因为生产环境是Windows 2008服务器(Dev是Ubuntu 12.04),制作东西并转换它看起来非常愚蠢.

有没有人这样做过?
我不想使用图书馆而迂腐吗?

解决方法:

borrowed from ask.yahoo

A PDF file starts with “%PDF-1.1” if it is a version 1.1 type of PDF file. You can read PDF files ok when they don’t have binary data objects stored in them, and you could even make one using Notepad if you didn’t need to store a binary object like a Paint bitmap in it.

But after seeing the “%PDF-1.1” you ignore what’s after that (Adobe Reader does, too) and go straight to the end of the file to where there is a line that says “%%EOF”. That’s always the last thing in the file; and if that’s there you know that just a few characters before that place in the file there’s the word “startxref” followed by a number. This number tells a reader program where to look in the file to find the start of the list of items describing the structure of the file. These items in the list can be page objects, dictionary objects, or stream objects (like the binary data of a bitmap), and each one has “obj” and “endobj” marking out where its description starts and ends.

For fairly simple PDF files, you might be able to type the text in just like you did with Notepad to make a working PDF file that Adobe Reader and other PDF viewer programs could read and display correctly.

Doing something like this is a challenge, even for a simple file, and you’d really have to know what you’re doing to get any binary data into the file where it’s supposed to go; but for character data, you’d just be able to type it in. And all of the commands used in the PDF are in the form of strings that you could type in. The hardest part is calculating those numbers that give the file offsets for items in the file (such as the number following “startxref”).

If the way the file format is laid out intrigues you, go ahead and read the PDF manual, which tells the whole story.
07001

但实际上你应该只使用一个库

感谢@LukasGraf提供此链接http://www.gnupdf.org/Introduction_to_PDF,它显示了如何从头开始创建一个简单的hello world pdf

上一篇:Oracle使用总结


下一篇:DBSCAN聚类算法简介