翻譯|使用教程|編輯:胡濤|2022-12-22 14:01:00.053|閱讀 193 次
概述:本教程展示了如何在 C# Windows 控制臺應用程序中使用 LEADTOOLS SDK 創建一個新的 PDF 文檔并將 PDF 文件的第一頁添加到其中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
LEADTOOLS是一個綜合工具包的集合,用于將識別、文檔、醫療、成像和多媒體技術整合到桌面、服務器、平板電腦、網絡和移動解決方案中,是一項企業級文檔自動化解決方案,有捕捉,OCR,OMR,表單識別和處理,PDF,打印捕獲,歸檔,注釋和顯示功能。利用業界領先的圖像處理技術,能夠智能識別文件,可以用來識別任何類型的掃描或傳真形式的圖像。
本教程展示了如何在 C# Windows 控制臺應用程序中使用 LEADTOOLS SDK 創建一個新的 PDF 文檔并將 PDF 文件的第一頁添加到其中。
| 概述 | |
|---|---|
| 概括 | 本教程介紹如何在 C# Windows 控制臺應用程序中使用 SVG 創建新的 PDF 文檔并向其添加頁面 |
| 完成時間 | 30分鐘 |
| 視覺工作室項目 | |
| 平臺 | C# Windows 控制臺應用程序 |
| 集成開發環境 | 視覺工作室 2017、2019 |
| 開發許可 | LEADTOOLS |
| 用另一種語言試試 |
|
在使用文件觀察器轉換文件 - C# .NET Core教程之前,通過查看添加引用和設置許可證教程熟悉創建項目的基本步驟。
教程中創建的項目副本開始。如果您沒有該項目,請按照該教程中的步驟創建它。
所需的參考取決于項目的目的。可以通過本地 DLL 引用添加引用。
本教程需要以下本地 DLL,它們位于<INSTALL_DIR>\LEADTOOLS22\Bin\Dotnet4\x64:
還需要以下非 LEADTOOLS DLL:
有關特定功能所需的 DLL 的完整列表,請參閱。
不同的 SDK 功能需要不同的引用。有關完整列表,請參閱。
設置許可證文件許可證解鎖項目所需的功能。它必須在調用任何工具包函數之前設置。有關詳細信息,包括針對不同平臺的教程,請參閱設置運行時許可證。
有兩種類型的運行時許可證:
筆記
添加 LEADTOOLS NuGet 引用和設置許可證在添加引用和設置許可證教程 中有更詳細的介紹。
創建項目、添加參考和設置許可證后,就可以開始編碼了。
在解決方案資源管理器中,打開Program.cs。添加一個新方法 called并在underCreatePdfDocument()的方法內部調用它。添加以下代碼以創建新的 PDF 文件,并將給定目錄中每個 PDF 的第一頁添加到新 PDF 中。Main()SetLicense();
【C#】
// Add to using block using System; using System.IO; using Leadtools; using Leadtools.Codecs; using Leadtools.Document.Writer;
【C#】
static void CreatePdfDocument()
{
using (RasterCodecs codecs = new RasterCodecs())
{
string dir = @"C:\LEADTOOLS22\Resources\Images";
int pageNumber = 1;
string[] pdfFiles = Directory.GetFiles( dir, "*.pdf");
DocumentFormat format = DocumentFormat.Pdf;
string outFile = Path.Combine(dir, "DocumentWriters." + DocumentWriter.GetFormatFileExtension(format));
codecs.Options.RasterizeDocument.Load.Resolution = 300;
DocumentWriter docWriter = new DocumentWriter();
PdfDocumentOptions pdfOptions = docWriter.GetOptions(format) as PdfDocumentOptions;
pdfOptions.DocumentType = PdfDocumentType.PdfA;
pdfOptions.ImageOverText = true;
docWriter.SetOptions(format, pdfOptions);
// Begin a new PDF document
docWriter.BeginDocument(outFile, format);
// Add the pages
foreach (string file in pdfFiles)
{
DocumentWriterSvgPage page = new DocumentWriterSvgPage();
page.SvgDocument = codecs.LoadSvg(file, pageNumber, null);
if (pdfOptions.ImageOverText)
{
// If we are using image/text, then load the overlay raster image
page.Image = codecs.Load(file, pageNumber);
}
// Add the page to the created PDF document
docWriter.AddPage(page);
Console.WriteLine($"Added page {pageNumber} from {Path.GetFileNameWithoutExtension(file)}\n");
// Dispose of resources
if (page.SvgDocument != null)
page.SvgDocument.Dispose();
if (page.Image != null)
page.Image.Dispose();
}
// Finalized document to disk
docWriter.EndDocument();
Console.WriteLine("PDF document saved successfully!");
}
}
按F5或選擇Debug -> Start Debugging運行項目。
如果正確執行了這些步驟,應用程序將運行并創建一個新的 PDF 文件,并使用 SVG 和 Document Writers 在給定目錄中添加每個 PDF 文件的第一頁。
以上便是使用文檔編寫器創建文檔,如果您還有其他疑問,歡迎咨詢我們或者加入我們官方技術交流群。
歡迎下載|體驗更多LEADTOOL產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn