Add annotation to PDF using plain C/C++ [closed]

自作多情 提交于 2019-12-23 06:44:31

问题


I am looking for a way to add a note to a PDF, only using plain C/C++ (without a third party library).

How can I get this result?


回答1:


Here is the PDF Reference Document Third Edition.

PDF files are composed by different binary objects, that can be compressed, encoded or encrypted using different algorithms, compression schemes (lossy and lossless) and encoding filters. Each object is referenced in a reference table with information on its position in the file. You will need to know how to deal with this table, you will need to implement all possible compression schemes, encodings filters and encryption algorithms, and then you will have to deal with all possible structures of PDF objects.

In the PDF specification, these objects are called dictionaries, and they are composed by entries. Each entry has a type that can be either a simple type, or another dictionary (or a reference to it), or an array of one more of these element types. So we can say that a PDF is basically a tree of dictionary objects.

Once your code is able to deal with every possible dictionary in the specification, and with the tree structure, you can go to Chapter 8 - Interactive features of the specification, part 8.4 - Annotations, and implement a way of adding annotation dictionaries to a PDF file.

You should notice that I am not even mentioning hot topics of PDF files such as Fonts, color spaces, transparencies, and drawing instructions inside a page. I am assumming you will be able to load all objects in a file, create an annotation object, insert it somehow on your objects tree, and save all objects again "as they are". This is more or less how iText works, so if you really want to implement this, you can take a look on the source code of iText so you can have a small window of the amount of work that this kind of project requires.

You may also want to take a look at this answer in SO.



来源:https://stackoverflow.com/questions/10716958/add-annotation-to-pdf-using-plain-c-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!