翻譯|使用教程|編輯:胡濤|2023-01-05 10:40:16.247|閱讀 181 次
概述:本文將為你介紹如何在 C++ 中將PDF轉(zhuǎn)換為Doc 、Docx 。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.PDF 是一款高級(jí)PDF處理API,可以在跨平臺(tái)應(yīng)用程序中輕松生成,修改,轉(zhuǎn)換,呈現(xiàn),保護(hù)和打印文檔。無需使用Adobe Acrobat。此外,API提供壓縮選項(xiàng),表創(chuàng)建和處理,圖形和圖像功能,廣泛的超鏈接功能,圖章和水印任務(wù),擴(kuò)展的安全控件和自定義字體處理。。本文將為你介紹如何在 C++ 中將PDF轉(zhuǎn)換為Doc 、Docx 。
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
在某些情況下,您可能需要將PNG、JPG或其他圖像文件轉(zhuǎn)換為PDF文檔。這在將掃描的發(fā)票頁面轉(zhuǎn)換為 PDF 等場(chǎng)景中可能很有用。在本文中,您將學(xué)習(xí)如何在 C# 中將圖像轉(zhuǎn)換為 PDF 格式。我們還將演示如何以編程方式將多個(gè)圖像轉(zhuǎn)換為 PDF。
對(duì)于圖像到 PDF 的轉(zhuǎn)換,我們將使用Aspose.PDF for .NET。它是一個(gè)功能強(qiáng)大的 PDF API,可讓您從 .NET 應(yīng)用程序中創(chuàng)建和操作 PDF 文件。此外,它還提供 PDF 文件的高保真來回轉(zhuǎn)換。您可以下載API 或使用NuGet安裝它。
PM> Install-Package Aspose.Pdf
讓我們先來看看如何在 C# 中將單個(gè)圖像轉(zhuǎn)換為 PDF 文件。以下是執(zhí)行此操作的步驟。
以下代碼示例顯示了如何在 C# 中將 PNG 圖像轉(zhuǎn)換為 PDF。
// Create a new document Document doc = new Document(); // Path of the image file string imageFile = @"aspose.png"; // Add a page to pages collection of document var page = doc.Pages.Add(); // Load image into stream FileStream imageStream = new FileStream(imageFile, 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 Aspose.Pdf.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("image-to-pdf.pdf");
以下是在 C# 中將多個(gè)圖像轉(zhuǎn)換為單個(gè) PDF 文件的步驟。
以下代碼示例顯示了在 C# 中將多個(gè)圖像轉(zhuǎn)換為單個(gè) 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 Pdf.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("multiple-images-to-pdf.pdf");
以上便是如何在 C# .NET 中將圖像轉(zhuǎn)換為 PDF詳細(xì)步驟 ,要是您還有其他關(guān)于產(chǎn)品方面的問題,歡迎咨詢我們,或者加入我們官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn