简体   繁体   English

PDFClown查找和替换页面

[英]PDFClown Find and replace page

Using pdfclown, 使用pdfclown,

I was wondering the best practice to find a page in a Existing PDF doc, and replace with a page from another PDF doc. 我想知道最佳做法是在现有PDF文档中查找页面,并替换为另一个PDF文档中的页面。

I have the bookmark and pagelabel of both pages. 我有两个页面的书签和pagelabel。

A simple example for replacing pages can be derived from the PageManager cli examples: 一个简单的替换页面的例子可以从PageManager cli例子中得到:

string inputA = @"A.pdf";
string inputB = @"B.pdf";
string output = @"A-withPage1FromB-simple.pdf";

org.pdfclown.files.File fileA = new org.pdfclown.files.File(inputA);
org.pdfclown.files.File fileB = new org.pdfclown.files.File(inputB);

// replace page 0 in fileA by page 0 from fileB
Document mainDocument = fileA.Document;
Bookmarks bookmarks = mainDocument.Bookmarks;
PageManager manager = new PageManager(mainDocument);
manager.Remove(0, 1);
manager.Add(0, fileB.Document.Pages.GetSlice(0, 1));

fileA.Save(output, SerializationModeEnum.Standard);

This indeed replaces the first page in A.pdf by the first page in B.pdf and saves the result as A-withPage1FromB-simple.pdf. 实际上,这确实将A.pdf中的第一页替换为B.pdf中的第一页,并将结果保存为A-withPage1FromB-simple.pdf。

Unfortunately, though, the PageManager does not update bookmarks. 但是,不幸的是, PageManager不会更新书签。 In the result of the code above, therefore, there still is a bookmarks which used to point to the original first page; 因此,在上面的代码结果中,仍然有一个书签用来指向原始的第一页; as this page is not there, anymore, it now points nowhere anymore. 由于此页面不存在,因此现在不再指向任何地方。 And the bookmark pointing to the first page in fileB, is ignored completely. 指向fileB第一页的书签将被完全忽略。

Other document level, page related properties also are not transferred, eg the page label. 其他文档级别的页面相关属性也不会传输,例如页面标签。 In case of the page labels, though, the original label for the first page remains associated to the first page after replacement. 但是,在使用页面标签的情况下,替换后的第一页原始标签仍与第一页相关联。 This is due to a different kind of reference (by page number, not by object). 这是由于引用类型不同(按页码而不是按对象)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM