翻譯|使用教程|編輯:李顯亮|2019-11-07 13:31:54.143|閱讀 298 次
概述:從PDF到HTML的轉(zhuǎn)換過(guò)程中,PDF文件中的圖像將保存到SVG。圖像在包含HTML頁(yè)面資源的文件夾中創(chuàng)建,并從同一文件夾引用。我們的一些客戶要求在將PDF轉(zhuǎn)換為HTML時(shí),在Aspose.PDF生成的SVG文件中添加URL前綴。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.PDF for .NET是一種高級(jí)PDF處理和解析API,用于在跨平臺(tái)應(yīng)用程序中執(zhí)行文檔管理和操作任務(wù)。API可以輕松用于生成,修改,轉(zhuǎn)換,渲染,保護(hù)和打印PDF文檔,而無(wú)需使用Adobe Acrobat。此外,還提供PDF壓縮選項(xiàng),表格創(chuàng)建和操作,圖形和圖像功能,廣泛的超鏈接功能,印章和水印任務(wù),擴(kuò)展的安全控制和自定義字體處理。
PDF是當(dāng)今最流行的文檔格式之一,各種應(yīng)用程序?qū)⑵溆米髯罱K輸出。由于支持多種數(shù)據(jù)類型和可移植性,因此它是創(chuàng)建和共享內(nèi)容的首選格式。作為對(duì)開(kāi)發(fā)文檔管理應(yīng)用程序感興趣的.NET應(yīng)用程序開(kāi)發(fā)人員,可能希望嵌入處理功能,以讀取PDF文檔并將其轉(zhuǎn)換為其他文件格式,例如HTML。
在本文中,我們將探索并演示Aspose.PDF for .NET API的強(qiáng)大轉(zhuǎn)換功能,以使用多種選項(xiàng)讀取PDF文件并將其轉(zhuǎn)換為HTML。
點(diǎn)擊下載最新版Aspose.PDF for .NET
從PDF到HTML的轉(zhuǎn)換過(guò)程中,PDF文件中的圖像將保存到SVG。圖像在包含HTML頁(yè)面資源的文件夾中創(chuàng)建,并從同一文件夾引用。我們的一些客戶要求在將PDF轉(zhuǎn)換為HTML時(shí),在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" />
可以通過(guò)以下自定義圖像保存策略來(lái)實(shí)現(xiàn)上述要求。
// 文檔目錄的路徑。 string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat(); Document testDoc = new Document(dataDir + "input.pdf"); HtmlSaveOptions options = new HtmlSaveOptions(); //這是允許進(jìn)行工作和測(cè)試測(cè)試功能的主要設(shè)置 options.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg;// options.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(Custom_processor_of_embedded_images); //進(jìn)行轉(zhuǎn)換 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; } }
還想要更多嗎?您可以點(diǎn)擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問(wèn)或需求,請(qǐng)隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。
如果您對(duì)Aspose有任何需求和疑難,記得掃描下方二維碼告訴我們哦~
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn