翻譯|行業資訊|編輯:胡濤|2024-09-04 15:12:19.693|閱讀 99 次
概述:在這篇博文中,我們將引導您完成使用 C# 將 JPG 圖像合并為 PDF 的過程。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.PDF 是一款高級PDF處理API,可以在跨平臺應用程序中輕松生成,修改,轉換,呈現,保護和打印文檔。無需使用Adobe Acrobat。此外,API提供壓縮選項,表創建和處理,圖形和圖像功能,廣泛的超鏈接功能,圖章和水印任務,擴展的安全控件和自定義字體處理。 接下來我們將為您介紹如何借助這款工具在程序中合并JPG文件。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
將多張JPG圖像合并為一個PDF是各種應用程序的常見要求,包括文檔管理系統、報告生成和數字存檔。在這篇博文中,我們將引導您完成使用 C# 將 JPG 圖像合并為 PDF 的過程。
我們將使用Aspose.PDF for .NET將 JPG 圖像合并到 PDF 中(使用 C#)。它是一個功能強大的 PDF 操作庫,使開發人員能夠在 .NET 應用程序中以編程方式創建、操作和管理 PDF 文檔。
請下載API 的DLL或使用以下命令使用NuGet安裝它:
PM> Install-Package Aspose.PDF
我們可以通過以下步驟輕松地將多張JPG圖像合并為一個PDF文檔:
以下代碼示例展示了如何在 C# 中將 JPG 圖像合并到 PDF 文檔中。
// Read all JPG files var fileStreams = Directory.GetFiles("D:\\Files\\images\\", "sam*.jpg") .OrderBy(f => f) .Select(f => File.OpenRead(f)) .Cast<Stream>() .ToList(); // Merge images in Stream Stream inputStream = PdfConverter.MergeImages(fileStreams, ImageFormat.Jpeg, ImageMergeMode.Vertical, 1, 1); // Create a PDF document and add the image to it Document doc = new Document(); Page page = doc.Pages.Add(); // Create an instance of the image class Image image = new Image(); // Set the image file stream image.ImageStream = inputStream; // Add the image into paragraphs collection of the section page.Paragraphs.Add(image); // Save the document doc.Save("merged-jpgs-to-PDF.pdf");
同樣的,我們可以按照以下步驟將多張JPG圖片合并為一個PDF文檔:
以下代碼示例展示了如何在 C# 中將多張 JPG 圖像合并為一個 PDF 文檔。
// Create a new document Document doc = new Document(); // Read all JPG files var fileList = Directory.GetFiles("D:\\Files\\images\\", "sam*.jpg") .OrderBy(f => f) .Select(f => File.OpenRead(f)) .Cast<Stream>() .ToList(); foreach (var file in fileList) { Console.WriteLine("Total Pages:" + doc.Pages.Count); // Add a page to pages collection of document var page = doc.Pages.Add(); // Create an image object Image image1 = new Image(); // Add the image into paragraphs collection of the section page.Paragraphs.Add(image1); // Set the image file stream image1.ImageStream = file; } // Save resultant PDF file doc.Save("multiple-images-to-pdf.pdf");
工具免費在線將您的 JPG 圖像合并為 PDF 文檔。
在本文中,我們學習了如何使用 C# 將 JPG 合并為 PDF。我們還了解了如何以編程方式將 JPG 圖像合并到 PDF 文檔中。按照本博客文章中概述的步驟,您可以輕松地從多幅圖像創建 PDF 文檔。
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn