使用纯C / C ++将注释添加到PDF [英] Add annotation to PDF using plain C/C++

查看:171
本文介绍了使用纯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).

我如何获得这个结果?

推荐答案

这里是 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天全站免登陆