翻譯|使用教程|編輯:胡濤|2022-12-22 14:01:00.053|閱讀 178 次
概述:本教程展示了如何在 C# Windows 控制臺應(yīng)用程序中使用 LEADTOOLS SDK 創(chuàng)建一個新的 PDF 文檔并將 PDF 文件的第一頁添加到其中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
LEADTOOLS是一個綜合工具包的集合,用于將識別、文檔、醫(yī)療、成像和多媒體技術(shù)整合到桌面、服務(wù)器、平板電腦、網(wǎng)絡(luò)和移動解決方案中,是一項企業(yè)級文檔自動化解決方案,有捕捉,OCR,OMR,表單識別和處理,PDF,打印捕獲,歸檔,注釋和顯示功能。利用業(yè)界領(lǐng)先的圖像處理技術(shù),能夠智能識別文件,可以用來識別任何類型的掃描或傳真形式的圖像。
本教程展示了如何在 C# Windows 控制臺應(yīng)用程序中使用 LEADTOOLS SDK 創(chuàng)建一個新的 PDF 文檔并將 PDF 文件的第一頁添加到其中。
概述 | |
---|---|
概括 | 本教程介紹如何在 C# Windows 控制臺應(yīng)用程序中使用 SVG 創(chuàng)建新的 PDF 文檔并向其添加頁面 |
完成時間 | 30分鐘 |
視覺工作室項目 | |
平臺 | C# Windows 控制臺應(yīng)用程序 |
集成開發(fā)環(huán)境 | 視覺工作室 2017、2019 |
開發(fā)許可 | LEADTOOLS |
用另一種語言試試 |
|
在使用文件觀察器轉(zhuǎn)換文件 - C# .NET Core教程之前,通過查看添加引用和設(shè)置許可證教程熟悉創(chuàng)建項目的基本步驟。
教程中創(chuàng)建的項目副本開始。如果您沒有該項目,請按照該教程中的步驟創(chuàng)建它。
所需的參考取決于項目的目的。可以通過本地 DLL 引用添加引用。
本教程需要以下本地 DLL,它們位于<INSTALL_DIR>\LEADTOOLS22\Bin\Dotnet4\x64:
還需要以下非 LEADTOOLS DLL:
有關(guān)特定功能所需的 DLL 的完整列表,請參閱。
不同的 SDK 功能需要不同的引用。有關(guān)完整列表,請參閱。
設(shè)置許可證文件許可證解鎖項目所需的功能。它必須在調(diào)用任何工具包函數(shù)之前設(shè)置。有關(guān)詳細信息,包括針對不同平臺的教程,請參閱設(shè)置運行時許可證。
有兩種類型的運行時許可證:
筆記
添加 LEADTOOLS NuGet 引用和設(shè)置許可證在添加引用和設(shè)置許可證教程 中有更詳細的介紹。
創(chuàng)建項目、添加參考和設(shè)置許可證后,就可以開始編碼了。
在解決方案資源管理器中,打開Program.cs。添加一個新方法 called并在underCreatePdfDocument()的方法內(nèi)部調(diào)用它。添加以下代碼以創(chuàng)建新的 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運行項目。
如果正確執(zhí)行了這些步驟,應(yīng)用程序?qū)⑦\行并創(chuàng)建一個新的 PDF 文件,并使用 SVG 和 Document Writers 在給定目錄中添加每個 PDF 文件的第一頁。
以上便是使用文檔編寫器創(chuàng)建文檔,如果您還有其他疑問,歡迎咨詢我們或者加入我們官方技術(shù)交流群。
歡迎下載|體驗更多LEADTOOL產(chǎn)品
您還可以加入產(chǎn)品技術(shù)交流Q群:731259648
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn