原創|使用教程|編輯:龔雪|2013-11-12 09:27:30.000|閱讀 957 次
概述:LEADTOOLS Document and Medical Imaging SDK可通過LEADTOOLS提供的先進PDF插件為.Net應用程序添加強大的PDF支持。除了加載和保存可檢索文本和圖像基礎的PDF文件,LEADTOOLS還可以提取和編輯文本(無需OCR)、合并、拆分頁面、閱讀和更新書簽、鏈接、跳轉和源數據等。接下來,我們將以示例的方式向大家展示LEADTOOLS的高級PDF插件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
PDF是使用最廣泛的文檔格式之一,因此,各軟件廠商竭力開發支持PDF的解決方案。LEADTOOLS Document and Medical Imaging SDK可通過LEADTOOLS提供的先進PDF插件為.Net應用程序添加強大的PDF支持。除了加載和保存可檢索文本和圖像基礎的PDF文件,LEADTOOLS還可以提取和編輯文本(無需OCR)、合并、拆分頁面、閱讀和更新書簽、鏈接、跳轉和源數據等。接下來,我們將以示例的方式向大家展示LEADTOOLS的高級PDF插件。
PDF Document功能:
PDF File功能:
LEADTOOLS先進的PDF功能建立在Leadtools.Pdf 命名空間的兩個類中: PDFFile和PDFDocument。PDFFile類用于修改元數據、頁面和轉換。 PDFDocument用于解析和修改PDF文件的文檔對象結構。
在下列示例中,我們使用 PDFFile和PDFDocumentProperties類來加載PDF文件,并修改元數據。
string fileName = @"C:\Document.pdf"; // Load it PDFFile file = new PDFFile(fileName); // Update the properties file.DocumentProperties = new PDFDocumentProperties(); file.DocumentProperties.Author = "Me"; file.DocumentProperties.Title = "My Title"; file.DocumentProperties.Subject = "My Subject"; file.DocumentProperties.Creator = "My Application"; file.DocumentProperties.Modified = DateTime.Now; // Save it file.SetDocumentProperties(null);
同樣,PDFFile類也提供了多種高級功能,如插入、刪除、合并PDF以及轉換等。下面的例子合并三個文件,并將這些文件轉換為PDF / A格式。
string fileName1 = @"C:\File1.pdf"; string fileName2 = @"C:\File2.pdf"; string fileName3 = @"C:\File3.pdf"; string finalFileName = @"C:\Final.pdf"; // Load first file PDFFile file = new PDFFile(fileName1); // Merge with second and third files, put the result in final file.MergeWith(new string[] { fileName2, fileName3 }, finalFileName); // Convert final file to PDF/A file = new PDFFile(finalFileName); file.ConvertToPDFA(null);
PDFDocument類提供了可檢索PDF功能。使用 PDFParsePagesOptions,你可以選擇解析PDF對象、字體、超鏈接等。在下面的例子中,我們將加載一個PDF文件,并在MessageBox中顯示文本。
string fileName = @"C:\Document.pdf"; // Create a PDF document PDFDocument document = new PDFDocument(fileName); // Parse the objects of the first page document.ParsePages(PDFParsePagesOptions.Objects, 1, 1); // Get the page PDFDocumentPage page = document.Pages[0]; // Use a StringBuilder to gather the text StringBuilder text = new StringBuilder(); // Loop through the objects foreach (PDFObject obj in page.Objects) { switch (obj.ObjectType) { case PDFObjectType.Text: // Add the text character code text.Append(obj.Code); // If this is the last object in a line, add a line terminator if (obj.TextProperties.IsEndOfLine) text.AppendLine(); break; case PDFObjectType.Image: case PDFObjectType.Rectangle: default: // Do nothing break; } } // Show the text MessageBox.Show(text.ToString());
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網