使用普通 C/C++ 向 PDF 添加注释 [英] Add annotation to PDF using plain C/C++

查看:64
本文介绍了使用普通 C/C++ 向 PDF 添加注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种向 PDF 添加注释的方法,只使用普通的 C/C++(没有第三方库).

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?

推荐答案

这里是 PDF 参考文档第三版.

PDF 文件由不同的二进制对象组成,可以使用不同的算法、压缩方案(有损和无损)和编码过滤器对这些对象进行压缩、编码或加密.每个对象都在引用表中引用,其中包含有关其在文件中的位置的信息.您将需要知道如何处理该表,您需要实现所有可能的压缩方案、编码过滤器和加密算法,然后您将不得不处理所有可能的 PDF 对象结构.

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.

在 PDF 规范中,这些对象称为字典,它们由条目组成.每个条目都有一个类型,可以是简单类型,也可以是另一个字典(或对它的引用),或者是这些元素类型中的一个或多个的数组.所以我们可以说一个PDF基本上是一个字典对象树.

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.

一旦您的代码能够处理规范中的每一个可能的字典,并且有了树结构,您就可以转到规范的第 8 章 - 交互功能,部分 8.4 -注释,并实现了一种向 PDF 文件添加注释字典的方法.

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.

您应该注意到,我什至没有提到 PDF 文件的热门话题,例如字体、色彩空间、透明度和页面内的绘图说明.我假设您将能够加载文件中的所有对象,创建注释对象,以某种方式将其插入到您的对象树中,并再次按原样"保存所有对象.这或多或少是 iText 的工作原理,所以如果你真的想实现这一点,你可以看看iText 的源代码,因此您可以通过一个小窗口了解此类项目所需的工作量.

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.

您可能还想看看 SO 中的这个答案.

这篇关于使用普通 C/C++ 向 PDF 添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆