翻譯|使用教程|編輯:李顯亮|2021-04-23 09:27:30.730|閱讀 272 次
概述:在不同情況下,您可能需要基于一堆圖像創建PDF,例如從掃描的文檔頁面或發票生成PDF。對于這種情況,本文介紹了如何使用C#以編程方式從圖像創建PDF。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在不同情況下,您可能需要基于一堆圖像創建PDF,例如從掃描的文檔頁面或發票生成PDF。對于這種情況,本文介紹了如何使用C#以編程方式從圖像創建PDF。
為了從圖像創建PDF文件,我們將使用.NET API的Aspose.PDF,它是功能強大的PDF API,可讓您從.NET應用程序中創建,修改和轉換PDF文件。 點擊下方可下載。
從圖像創建PDF文件的步驟
以下是使用Aspose.PDF for .NET從圖像創建PDF的步驟。
使用C#從圖像創建PDF
以下是從圖像創建PDF的步驟以及API參考。
以下代碼示例顯示了如何從圖像創建PDF。
// Create a new document Document doc = new Document(); // Access image files in the folder string[] fileList = Directory.GetFiles(@"D:/images/"); foreach (String file in fileList) { // Add a page to pages collection of document var page = doc.Pages.Add(); // Load image into stream FileStream imageStream = new FileStream(file, FileMode.Open); // Set margins so image will fit, etc. page.PageInfo.Margin.Bottom = 0; page.PageInfo.Margin.Top = 0; page.PageInfo.Margin.Left = 0; page.PageInfo.Margin.Right = 0; page.CropBox = new Rectangle(0, 0, 400, 400); // 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 = imageStream; } // Save resultant PDF file doc.Save("document.pdf");
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn