编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Aspose.Pdf使用教程:在PDF文档中添加书签

wxchong 2024-07-15 10:07:03 开源技术 71 ℃ 0 评论

可以使用OutlineItemCollection在PDF文档中添加书签。 首先,你需要使用文档对象打开PDF文档。在那之后,你可以在文档对象的Outlines集合中添加OutlineItemCollection。然而,在将OutlineItemCollection添加到Outlines集合之前,你需要定义书签的属性。

下面是在PDF文件中添加书签的代码片段

C#

//open document

Document pdfDocument = new Document("input.pdf");

//create a bookmark object

OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

pdfOutline.Title = "Test Outline";

pdfOutline.Italic = true;

pdfOutline.Bold = true;

//set the destination page number

pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(doc.Pages[1]);

//add bookmark in the document's outline collection.

pdfDocument.Outlines.Add(pdfOutline);

//save output

pdfDocument.Save("output.pdf");

VB.NET

'open document

Dim pdfDocument As New Document("input.pdf")

'create a bookmark object

Dim pdfOutline As New OutlineItemCollection(pdfDocument.Outlines)

pdfOutline.Title = "Test Outline"

pdfOutline.Italic = True

pdfOutline.Bold = True

'set the destination page number

pdfOutline.Action = New Aspose.Pdf.InteractiveFeatures.GoToAction(doc.Pages(1))

'add bookmark in the document's outline collection.

pdfDocument.Outlines.Add(pdfOutline)

'save output

pdfDocument.Save("output.pdf")

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表