且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iTextSharp-将元素从一个PDF复制到另一个

更新时间:2023-11-27 22:26:10

此任务非常复杂.我为大型贺卡制造商编写了一个程序来执行此操作.

This task is very complex. I wrote a program to do this for a large greeting card maker.

首先,您必须找到文本并计算字形边界框.接下来,您必须修改内容流以删除文本.根据PDF创建者的不同,文本可能会分成许多部分.您必须从内容流中删除这些运算符,并调整CTM,因为某些运算符使用相对定位.最后,您必须插入与原始文本的样式(字体,大小,颜色,方向等)匹配的替换文本

First you have to locate the text and calculate the glyph bounding boxes. Next you have to modify the contents stream to remove the text. The text may be broken into many pieces depending on the PDF creator. You have to remove those operators from the contents stream and adjust the CTM because some operators use relative positioning. Finally, you have to insert the replacement text, matching the original text's style (font, size, color, orientation, etc.)

对于将元素从一个PDF复制到另一个PDF,需要上述大多数步骤,而且还必须复制资源.字体,色彩空间,图案等,转换为新的PDF.

As for copying elements from one PDF to another, most of the steps above are required plus you have to copy resources, eg. fonts, colorspaces, patterns, etc, to the new PDF.