C# aspose.pdf需要把PDF中的某页复制到另一个PDF中第2页里面

C# aspose.pdf
需要把PDF中的某页复制到另一个PDF中第2页中。也就是在一个pdf文件中的第二页插入一个已存在的pdf。
QQ截图20190826130709.jpg (98.9 KB)

@fhn123456

感谢您与支持人员联系。

您可以使用insert方法将页面插入PDF文档。 请尝试以下代码,然后与我们分享您的反馈。

Document source = new Document(dataDir + "source.pdf");
Document destination = new Document(dataDir + "destination.pdf");
destination.Pages.Insert(2, source.Pages[1]);
destination.Save(dataDir + "updated_19.8.pdf");

如果您需要任何进一步的帮助,请联系我们。

1 Like

谢谢你,小弟还有一个小问题,aspose.pdf如何向已有书签插入书签到指定位置

       Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("cc.pdf");
        //创建书签对象
        Aspose.Pdf.OutlineItemCollection pdfOutline = new 
 OutlineItemCollection(pdfDocument.Outlines);
        pdfOutline.Title = "目录";
        //pdfOutline.Italic1 = true;
        //pdfOutline.Bold = true;pdfDocument.Pages[2], 700 InteractiveFeatures.FitHExplicitDestination

        pdfOutline.Destination = new FitExplicitDestination(2);
        //设定目标页面 
        pdfOutline.Action = new GoToAction(pdfDocument.Pages[1]);
        //在文档集合中添加书签。

        pdfDocument.Outlines.Add(pdfOutline);

        pdfDocument.Save("output.pdf");

QQ截图20190826232150.jpg (36.4 KB)

@fhn123456

如果要在特定位置插入书签,则可以使用OutlineItemCollection.Insert方法。 如果您的要求不同,请说明输入和预期的输出文件。

这个之前小弟用过了,报错: pdfOutline.Insert(2, pdfOutline);

System.ArgumentException:“Invalid index: index should be in the range [1…n] where n equals to the outline items count.”

QQ截图20190827071350.jpg (59.8 KB)

哥,小弟有一个问题还没解决呢,
这个之前小弟用过了,报错:pdfOutline.Insert(2,pdfOutline);

System.ArgumentException:“索引无效:索引应该在[1 … n]范围内,其中n等于大纲项目计数。”

@fhn123456

请分享缩小的代码段和源文件,以便我们可以尝试重现和调查它。

源文件:cc.pdf (4.0 MB)

1:使用pdfOutline.Insert()方法如何将书签插入到第一个书签的位置。
使用pdfOutline.Insert(1,pdfOutline);报这个错误:
System.ArgumentException:“索引无效:索引应该在[1 … n ]的范围内,其中ñ等于大纲项目计数“。

// 2,添加书签代码如下:
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(“cc.pdf”);

//创建书签对象
Aspose.Pdf.OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

pdfOutline.Title =“目录”;

//设定目标页面
pdfOutline.Action = new GoToAction(pdfDocument.Pages [1]);

强调文本 //在指定位置添加书签
pdfOutline.Insert(1,pdfOutline);

pdfDocument.Outlines.Add(pdfOutline);
//保存
pdfDocument.Save(“输出.pdf”);

@fhn123456

我们已经能够重现该问题并在我们的问题管理系统中将其记录为PDFNET-46910。 一旦有任何更新,我们会通知您。