翻譯|使用教程|編輯:李顯亮|2020-01-08 11:11:43.223|閱讀 419 次
概述:在本文中,我們將探索并演示Aspose.PDF for .NET API的強(qiáng)大轉(zhuǎn)換功能,將PDF文件轉(zhuǎn)換為HTML格式時(shí),將以與輸入PDF文檔相同的尺寸保存輸出文件。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
PDF是當(dāng)今最流行的文檔格式之一,各種應(yīng)用程序?qū)⑵溆米髯罱K輸出。由于支持多種數(shù)據(jù)類型和可移植性,因此它是創(chuàng)建和共享內(nèi)容的首選格式。作為對(duì)開發(fā)文檔管理應(yīng)用程序感興趣的.NET應(yīng)用程序開發(fā)人員,可能希望嵌入處理功能,以讀取PDF文檔并將其轉(zhuǎn)換為其他文件格式,例如HTML。
Aspose.PDF for .NET是一種高級(jí)PDF處理和解析API,用于在跨平臺(tái)應(yīng)用程序中執(zhí)行文檔管理和操作任務(wù)。API可以輕松用于生成,修改,轉(zhuǎn)換,渲染,保護(hù)和打印PDF文檔,而無需使用Adobe Acrobat。
在本文中,我們將探索并演示Aspose.PDF for .NET API的強(qiáng)大轉(zhuǎn)換功能,將PDF文件轉(zhuǎn)換為HTML格式時(shí),將以與輸入PDF文檔相同的尺寸保存輸出文件。
點(diǎn)擊下載最新版Aspose.PDF for .NET
將PDF文件轉(zhuǎn)換為HTML格式時(shí),將以與輸入PDF文檔相同的尺寸保存輸出文件。但是,有時(shí)您需要生成具有特定尺寸的輸出HTML。使用Aspose.PDF.Facades.PdfPageEditor和HtmlSaveOptions類來滿足此要求。
PdfPageEditorAspose.PDF.Facades命名空間中的類提供了更新或操作PDF文檔中頁面的功能。它還提供了設(shè)置或更新輸入PDF文件的頁面尺寸的功能。在轉(zhuǎn)換為HTML時(shí)設(shè)置特定尺寸:
以下代碼段顯示了轉(zhuǎn)換PDF文件HTML格式并為輸出文件指定尺寸的步驟。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat(); // Select desirable page size float newPageWidth = 400f; float newPageHeight = 400f; // Tune PdfPageEditor class Aspose.Pdf.Facades.PdfPageEditor pdfEditor = new Aspose.Pdf.Facades.PdfPageEditor(); // Bind source PDF file pdfEditor.BindPdf(dataDir + "input.pdf"); // Set the page dimensions pdfEditor.PageSize = new Aspose.Pdf.PageSize(newPageWidth, newPageHeight); // Set vertical alignment for page as center aligned pdfEditor.VerticalAlignmentType = Aspose.Pdf.VerticalAlignment.Center; // Set Horizontal alignment for page as center aligned pdfEditor.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center; // This scales page content to fit width, // Comment it out or set Zoom to 1.0F if You don't want to scale // Content and only want to change page's size (i.e. crop it) float zoom = Math.Min((float)newPageWidth / (float)pdfEditor.Document.Pages[1].Rect.Width, (float)newPageHeight / (float)pdfEditor.Document.Pages[1].Rect.Height); pdfEditor.Zoom = zoom;// (float)595; // Create stream object to hold file with updated dimensions MemoryStream output = new MemoryStream(); // Save file to stream object pdfEditor.Save(output); // Then reload scaled document and save it to HTML Document exportDoc = new Document(output); HtmlSaveOptions htmlOptions = new HtmlSaveOptions(); // This code shows page boreder in result - sometimes it comes in handy to see borders SaveOptions.BorderPartStyle borderStyle = new SaveOptions.BorderPartStyle(); borderStyle.LineType = SaveOptions.HtmlBorderLineType.Dotted; borderStyle.Color = System.Drawing.Color.Gray; htmlOptions.PageBorderIfAny = new SaveOptions.BorderInfo(borderStyle); // Conversion to HTML itself exportDoc.Save(dataDir + "SetOutputFileDimensions_out.html", htmlOptions); // Close the stream object output.Close();還想要更多嗎?您可以點(diǎn)擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請(qǐng)隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn