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

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

LEADTOOLS PDF插件功能:

PDF Document功能:字体

  • 加载和查看任何PDF文档
  • 提取文本(字,词,线),字体,图像以及带有位置和大小的超连接和矩形
  • 全面支持unicode,包括中文,日文,阿拉伯语和希伯来语
  • 经过读取PDF书签(阅读目录)和内部连接来解析文档结构
  • 生成光栅图像或缩略图

PDF File功能:优化

  • 全面支持多页:
    • 将现成PDF文档合并为单个PDF
    • 将单个PDF拆分为多页PDF
    • 提取,删除,插入和替换现有PDF文件中的任意页面
  • 读取和更新现成PDF文件的目录(TOC)
  • 将任意现有PDF文档转换为PDF/A
  • 线性化(优化用于Web查看)任意现有PDF
  • 加密/解密文档
  • 读写和更新全部PDF元数据,如做者、标题、主题和关键字
  • 读写和更新PDF文件目录

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

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

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";code

// 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);
unicode

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());

相关文章
相关标签/搜索