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

相關文章
相關標籤/搜索