翻譯|使用教程|編輯:李顯亮|2020-01-08 11:11:43.223|閱讀 419 次
概述:在本文中,我們將探索并演示Aspose.PDF for .NET API的強大轉換功能,將PDF文件轉換為HTML格式時,將以與輸入PDF文檔相同的尺寸保存輸出文件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
PDF是當今最流行的文檔格式之一,各種應用程序將其用作最終輸出。由于支持多種數據類型和可移植性,因此它是創建和共享內容的首選格式。作為對開發文檔管理應用程序感興趣的.NET應用程序開發人員,可能希望嵌入處理功能,以讀取PDF文檔并將其轉換為其他文件格式,例如HTML。
Aspose.PDF for .NET是一種高級PDF處理和解析API,用于在跨平臺應用程序中執行文檔管理和操作任務。API可以輕松用于生成,修改,轉換,渲染,保護和打印PDF文檔,而無需使用Adobe Acrobat。
在本文中,我們將探索并演示Aspose.PDF for .NET API的強大轉換功能,將PDF文件轉換為HTML格式時,將以與輸入PDF文檔相同的尺寸保存輸出文件。
將PDF文件轉換為HTML格式時,將以與輸入PDF文檔相同的尺寸保存輸出文件。但是,有時您需要生成具有特定尺寸的輸出HTML。使用Aspose.PDF.Facades.PdfPageEditor和HtmlSaveOptions類來滿足此要求。
PdfPageEditorAspose.PDF.Facades命名空間中的類提供了更新或操作PDF文檔中頁面的功能。它還提供了設置或更新輸入PDF文件的頁面尺寸的功能。在轉換為HTML時設置特定尺寸:
以下代碼段顯示了轉換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();還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn