翻譯|使用教程|編輯:李顯亮|2019-08-02 11:51:36.770|閱讀 416 次
概述:Aspose.PDF for .NET是一種高PDF處理和解析API,用于在跨平臺(tái)應(yīng)用程序中執(zhí)行文檔管理和操作任務(wù)。API可以輕松用于生成、修改、轉(zhuǎn)換、渲染、保護(hù)和打印PDF文檔,而無(wú)需使用Adobe Acrobat。本文介紹了如何添加和刪除注釋。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.PDF for .NET是一種高PDF處理和解析API,用于在跨平臺(tái)應(yīng)用程序中執(zhí)行文檔管理和操作任務(wù)。API可以輕松用于生成、修改、轉(zhuǎn)換、渲染、保護(hù)和打印PDF文檔,而無(wú)需使用Adobe Acrobat。此外,API還提供PDF壓縮選項(xiàng),表格創(chuàng)建和操作,圖形和圖像功能,廣泛的超鏈接功能,印章和水印任務(wù),擴(kuò)展的安全控制和自定義字體處理。
【下載體驗(yàn)Aspose.PDF for .NET最新版】
在接下來(lái)的系列教程中,將為開(kāi)發(fā)者帶來(lái)Aspose.PDF for .NET的一系列使用教程,例如進(jìn)行文檔間的轉(zhuǎn)換,如何標(biāo)記PDF文件,如何使用表單和圖表等等。
PDF文檔中的注釋包含在Page對(duì)象的Annotations集合中。此集合僅包含該單個(gè)頁(yè)面的所有注釋:每個(gè)頁(yè)面都有自己的Annotations集合。要向特定頁(yè)面添加注釋,請(qǐng)Annotations使用該Add方法將其添加到該頁(yè)面的集合中。要將SWF文件作為注釋包含在PDF文檔中,請(qǐng)使用命名空間中的ScreenAnnotation類Aspose.PDF.InteractiveFeatures.Annotations。
ScreenAnnotation 有三個(gè)參數(shù):
要添加SWF文件作為注釋:
下面的代碼片段向您展示了如何在PDF頁(yè)面中添加SWF注釋:
//指向documents目錄的路徑 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); // 打開(kāi)PDF文件 Document doc = new Document(dataDir + "AddSwfFileAsAnnotation.pdf"); // 獲取需要添加注釋的頁(yè)面的引用 Page page = doc.Pages[1]; // 使用.swf多媒體文件作為參數(shù)創(chuàng)建ScreenAnnotation對(duì)象 ScreenAnnotation annotation = new ScreenAnnotation(page, new Aspose.Pdf.Rectangle(0, 400, 600, 700), dataDir + "input.swf"); // 將注釋添加到頁(yè)面的注釋集合中 page.Annotations.Add(annotation); dataDir = dataDir + "AddSwfFileAsAnnotation_out.pdf"; //保存帶有注釋的更新PDF文檔 doc.Save(dataDir);
一個(gè)Page對(duì)象的AnnotationCollection集合包含對(duì)特定頁(yè)面的所有注釋。要從頁(yè)面中刪除所有注釋,請(qǐng)調(diào)用集合的Delete方法AnnotationCollectoin。
以下代碼段顯示了如何從特定頁(yè)面刪除所有注釋:
// 文檔目錄的路徑 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打開(kāi)文檔 Document pdfDocument = new Document(dataDir + "DeleteAllAnnotationsFromPage.pdf"); //刪除特定注釋 pdfDocument.Pages[1].Annotations.Delete(); dataDir = dataDir + "DeleteAllAnnotationsFromPage_out.pdf"; //保存更新的文檔 pdfDocument.Save(dataDir);
要從PDF中刪除特定注釋,請(qǐng)調(diào)用AnnotationCollection集合的Delete方法。此集合屬于該P(yáng)age對(duì)象。該Delete方法需要您要?jiǎng)h除的注釋的索引。然后,保存更新的PDF文件。以下代碼段顯示了如何刪除特定注釋:
// 文檔目錄的路徑 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打開(kāi)文檔 Document pdfDocument = new Document(dataDir + "DeleteParticularAnnotation.pdf"); //刪除特定注釋 pdfDocument.Pages[1].Annotations.Delete(1); dataDir = dataDir + "DeleteParticularAnnotation_out.pdf"; // 保存更新的文檔 pdfDocument.Save(dataDir);
Aspose.PDF允許您從整個(gè)文檔或給定頁(yè)面獲取注釋。要從PDF文檔中的頁(yè)面獲取所有注釋,請(qǐng)遍歷AnnotationCollection所需頁(yè)面資源的集合。以下代碼段顯示了如何獲取頁(yè)面的所有注釋:
//文檔目錄的路徑 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打開(kāi)文檔 Document pdfDocument = new Document(dataDir + "GetAllAnnotationsFromPage.pdf"); //遍歷所有注釋 foreach (MarkupAnnotation annotation in pdfDocument.Pages[1].Annotations) { //獲取注釋屬性 Console.WriteLine("Title : {0} ", annotation.Title); Console.WriteLine("Subject : {0} ", annotation.Subject); Console.WriteLine("Contents : {0} ", annotation.Contents); }
注釋與單個(gè)頁(yè)面相關(guān)聯(lián)并存儲(chǔ)在Page對(duì)象的AnnotationCOllection集合中。要獲取特定注釋,請(qǐng)指定其索引。例如,這返回一個(gè)Annotation需要轉(zhuǎn)換為特定注釋類型的對(duì)象TextAnnotation。以下代碼段顯示了如何獲取特定注釋及其屬性:
//文檔目錄的路徑 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打開(kāi)文檔 Document pdfDocument = new Document(dataDir + "GetParticularAnnotation.pdf"); //獲取特定注釋 TextAnnotation textAnnotation = (TextAnnotation)pdfDocument.Pages[1].Annotations[1]; //獲取注釋屬性 Console.WriteLine("Title : {0} ", textAnnotation.Title); Console.WriteLine("Subject : {0} ", textAnnotation.Subject); Console.WriteLine("Contents : {0} ", textAnnotation.Contents);
Aspose.PDF允許您從整個(gè)文檔或給定頁(yè)面獲取注釋資源。以下代碼片段顯示了如何獲取注釋資源作為輸入PDF文件的FileSpecification對(duì)象:
// 文檔目錄的路徑 string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations(); //打開(kāi)文檔 Document doc = new Document(dataDir + "AddAnnotation.pdf"); //創(chuàng)建注釋 ScreenAnnotation sa = new ScreenAnnotation(doc.Pages[1], new Rectangle(100, 400, 300, 600), dataDir + "AddSwfFileAsAnnotation.swf"); doc.Pages[1].Annotations.Add(sa); //保存文檔 doc.Save(dataDir + "GetResourceOfAnnotation_Out.pdf"); //打開(kāi)文檔 Document doc1 = new Document(dataDir + "GetResourceOfAnnotation_Out.pdf"); //獲取注釋的操作 RenditionAction action = (doc.Pages[1].Annotations[1] as ScreenAnnotation).Action as RenditionAction; //獲取演繹動(dòng)作的再現(xiàn) Rendition rendition = ((doc.Pages[1].Annotations[1] as ScreenAnnotation).Action as RenditionAction).Rendition; //媒體剪輯 MediaClip clip = (rendition as MediaRendition).MediaClip; FileSpecification data = (clip as MediaClipData).Data; MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[1024]; int read = 0; //可以在FileSpecification.Contents中訪問(wèn)媒體數(shù)據(jù) Stream source = data.Contents; while ((read = source.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } Console.WriteLine(rendition.Name); Console.WriteLine(action.RenditionOperation);
*想要購(gòu)買Aspose.PDF for .NET正版授權(quán)的朋友可以了解詳情哦~
歡迎加入ASPOSE技術(shù)交流QQ群,各類資源及時(shí)分享,技術(shù)問(wèn)題交流討論!(掃描下方二維碼加入群聊)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn