翻譯|使用教程|編輯:李顯亮|2019-11-07 13:31:54.143|閱讀 298 次
概述:從PDF到HTML的轉換過程中,PDF文件中的圖像將保存到SVG。圖像在包含HTML頁面資源的文件夾中創建,并從同一文件夾引用。我們的一些客戶要求在將PDF轉換為HTML時,在Aspose.PDF生成的SVG文件中添加URL前綴。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.PDF for .NET是一種高級PDF處理和解析API,用于在跨平臺應用程序中執行文檔管理和操作任務。API可以輕松用于生成,修改,轉換,渲染,保護和打印PDF文檔,而無需使用Adobe Acrobat。此外,還提供PDF壓縮選項,表格創建和操作,圖形和圖像功能,廣泛的超鏈接功能,印章和水印任務,擴展的安全控制和自定義字體處理。
PDF是當今最流行的文檔格式之一,各種應用程序將其用作最終輸出。由于支持多種數據類型和可移植性,因此它是創建和共享內容的首選格式。作為對開發文檔管理應用程序感興趣的.NET應用程序開發人員,可能希望嵌入處理功能,以讀取PDF文檔并將其轉換為其他文件格式,例如HTML。
在本文中,我們將探索并演示Aspose.PDF for .NET API的強大轉換功能,以使用多種選項讀取PDF文件并將其轉換為HTML。
從PDF到HTML的轉換過程中,PDF文件中的圖像將保存到SVG。圖像在包含HTML頁面資源的文件夾中創建,并從同一文件夾引用。我們的一些客戶要求在將PDF轉換為HTML時,在Aspose.PDF生成的SVG文件中添加URL前綴。
在高版本中,可以指定圖像的URL:
<image x="0" y="0" xlink:href="//localhost:255/img_01.png" temp_href="//localhost:255/img_01.png" width="1351" height="2135" />
可以通過以下自定義圖像保存策略來實現上述要求。
// 文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat(); Document testDoc = new Document(dataDir + "input.pdf"); HtmlSaveOptions options = new HtmlSaveOptions(); //這是允許進行工作和測試測試功能的主要設置 options.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg;// options.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(Custom_processor_of_embedded_images); //進行轉換 testDoc.Save(dataDir + @"PrefixForURLs_out.html", options);
private static string Custom_processor_of_embedded_images(SaveOptions.ResourceSavingInfo resourceSavingInfo) { // ____________________________________________________________________________ // This sample method saving strategy method saves image-files in some folder // (including raster image files that are exctracted from that SVGs) // Then it returns specific custom artificial path // to be used as value of 'src' or 'data' relevant attribute in generated host-SVG(or HTML) // ____________________________________________________________________________ //--------------------------------------------------------- // 1) All other files(f.e. fonts) will be processed with converter itself cause for them flag // resourceSavingInfo.CustomProcessingCancelled is set to 'true' //--------------------------------------------------------- if (!(resourceSavingInfo is HtmlSaveOptions.HtmlImageSavingInfo)) { resourceSavingInfo.CustomProcessingCancelled = true; return ""; } //--------------------------------------------------------- // 1) Create target folder if not created yet //--------------------------------------------------------- string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat(); string outDir = dataDir + @"output\36297_files\"; string outPath = outDir + Path.GetFileName(resourceSavingInfo.SupposedFileName); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } //--------------------------------------------------------- // 3) Write supplied image to that folder //--------------------------------------------------------- System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream); System.IO.File.WriteAllBytes(dataDir, reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length)); //--------------------------------------------------------- // 4) Return customized specific URL to be used to refer // just created image in parent SVG (or HTML) //--------------------------------------------------------- HtmlSaveOptions.HtmlImageSavingInfo asHtmlImageSavingInfo = resourceSavingInfo as HtmlSaveOptions.HtmlImageSavingInfo; if (asHtmlImageSavingInfo.ParentType == HtmlSaveOptions.ImageParentTypes.SvgImage) { return "// Localhost:255/" + resourceSavingInfo.SupposedFileName; } else { return "// Localhost:GetImage/imageID=" + resourceSavingInfo.SupposedFileName; } }
還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和咨詢。
如果您對Aspose有任何需求和疑難,記得掃描下方二維碼告訴我們哦~
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn