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

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

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文件的文档对象结构。

在下列示例中,我们使用 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());

转载于:https://www.cnblogs.com/leadtools/p/3418992.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值