PDF是使用最普遍的文檔格式之一,所以,各軟件廠商竭力開發支持PDF的解決方案。LEADTOOLS Document and Medical Imaging SDK可經過LEADTOOLS提供的先進PDF插件爲.Net應用程序添增強大的PDF支持。除了加載和保存可檢索文本和圖像基礎的PDF文件,LEADTOOLS還能夠提取和編輯文本(無需OCR)、合併、拆分頁面、閱讀和更新書籤、連接、跳轉和源數據等。接下來,咱們將以示例的方式向你們展現LEADTOOLS的高級PDF插件。
oop
PDF Document功能:字體
PDF File功能:優化
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());