趣百科

LEADTOOLS使用教程:读写、编辑PDF文件和元数据

编辑:Simone 2025-01-26 20:07:09 618 阅读

LEADTOOLS使用教程:读写、编辑PDF文件和元数据

LEADTOOLS Document and Medical Imaging SDK可通过LEADTOOLS提供的先进PDF插件为.Net应用程序添加强大的PDF支持。除了加载和保存可检索文本和图像基础的PDF文件,LEADTOOLS还可以提取和编辑文本(无需OCR)、合并、拆分页面、阅读和更新书签、链接、跳转和源数据等。接下来,我们将以示例的方式向大家展示LEADTOOLS的高级PDF插件。

PDF是使用最广泛的文档格式之一,因此,各软件厂商竭力开发支持PDF的解决方案。LEADTOOLS Document and Medical Imaging SDK可通过LEADTOOLS提供的先进PDF插件为.Net应用程序添加强大的PDF支持。除了加载和保存可检索文本和图像基础的PDF文件,LEADTOOLS还可以提取和编辑文本(无需OCR)、合并、拆分页面、阅读和更新书签、链接、跳转和源数据等。接下来,我们将以示例的方式向大家展示LEADTOOLS的高级PDF插件。

LEADTOOLS PDF插件功能:

PDF Document功能:

1、加载和查看任何PDF文档

2、提取文本(字,词,线),字体,图像以及带有位置和大小的超链接和矩形

3、全面支持unicode,包括中文,日文,阿拉伯语和希伯来语

4、通过读取PDF书签(阅读目录)和内部链接来解析文档结构

5、生成光栅图像或缩略图

PDF File功能:

1、读取和更新现成PDF文件的目录(TOC)

2、将任意现有PDF文档转换为PDF/A

3、线性化(优化用于Web查看)任意现有PDF

4、加密/解密文档

5、读写和更新所有PDF元数据,如作者、标题、主题和关键字

6、读写和更新PDF文件目录

LEADTOOLS先进的PDF功能建立在Leadtools.Pdf 命名空间的两个类中: PDFFile和PDFDocument。PDFFile类用于修改元数据、页面和转换。 PDFDocument用于解析和修改PDF文件的文档对象结构。

在下列示例中,我们使用 PDFFile和PDFDocumentProperties类来加载PDF文件,并修改元数据。

string fileName = @"C:\Document.pdf";// Load itPDFFile file = new PDFFile(fileName);// Update the propertiesfile.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 itfile.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 filePDFFile file = new PDFFile(fileName1);// Merge with second and third files, put the result in finalfile.MergeWith(new string[] { fileName2, fileName3 }, finalFileName);// Convert final file to PDF/Afile = new PDFFile(finalFileName);file.ConvertToPDFA(null);

PDFDocument类提供了可检索PDF功能。使用 PDFParsePagesOptions,你可以选择解析PDF对象、字体、超链接等。在下面的例子中,我们将加载一个PDF文件,并在MessageBox中显示文本。

string fileName = @"C:\Document.pdf";// Create a PDF documentPDFDocument document = new PDFDocument(fileName);// Parse the objects of the first pagedocument.ParsePages(PDFParsePagesOptions.Objects, 1, 1);// Get the pagePDFDocumentPage page = document.Pages;// Use a StringBuilder to gather the textStringBuilder text = new StringBuilder();// Loop through the objectsforeach (PDFObject obj in page.Objects){switch (obj.ObjectType){case PDFObjectType.Text:// Add the text character codetext.Append(obj.Code);// If this is the last object in a line, add a line terminatorif (obj.TextProperties.IsEndOfLine)text.AppendLine();break;case PDFObjectType.Image:case PDFObjectType.Rectangle:default:// Do nothingbreak;}}// Show the textMessageBox.Show(text.ToString());

版权声明:本站【趣百科】文章素材来源于网络或者用户投稿,未经许可不得用于商用,如转载保留本文链接:https://www.qubaik.com/life/124850.html

相关推荐