使用Aspose.PDF for .NET将PDF转换为HTML格式示例解读(2)——将CSS拆分为页面

Aspose.PDF for .NET是一种高级PDF处理和解析API,用于在跨平台应用程序中执行文档管理和操作任务。API可以轻松用于生成,修改,转换,渲染,保护和打印PDF文档,而无需使用Adobe Acrobat。此外,还提供PDF压缩选项,表格创建和操作,图形和图像功能,广泛的超链接功能,印章和水印任务,扩展的安全控制和自定义字体处理。

PDF是当今最流行的文档格式之一,各种应用程序将其用作最终输出。由于支持多种数据类型和可移植性,因此它是创建和共享内容的首选格式。作为对开发文档管理应用程序感兴趣的.NET应用程序开发人员,可能希望嵌入处理功能,以读取PDF文档并将其转换为其他文件格式,例如HTML。


PDF转HTML-将CSS拆分为页面

将PDF文件转换为HTML时,将创建一个包含格式信息的CSS文件。Aspose.PDF for .NET还提供了将输出HTML拆分为页面的功能,还可以将CSS拆分为多个页面。

本HtmlSaveOptions类有一个名为属性SplitIntoPages,它支持的功能和生成文件时输出HTML文件拆分页面。如果希望基于单个页面拆分CSS文件,而不是生成单个CSS文件。要做到这一点,我们引入了一个新的标志,SplitCssIntoPages对HtmlSaveOptions类。当此属性的值设置为true时,转换器将根据创建的单个HTML页面将outout CSS分为多个部分/页面。以下代码段显示了如何使用该标志。

//文档目录的路径。string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();// 1)清理目标文件夹string htmlFile = Path.GetFullPath(dataDir + "resultant.html");string imagesDir = Path.GetDirectoryName(htmlFile) + @"35942_files";string cssDir = Path.GetDirectoryName(htmlFile) + @"35942_css_files";if (Directory.Exists(imagesDir)) { Directory.Delete(imagesDir, true); };if (Directory.Exists(cssDir)) { Directory.Delete(cssDir, true); };// 2)创建要转换的文档Document pdfDocument = new Document(dataDir + "input.pdf");//  3)音调转换选项HtmlSaveOptions options = new HtmlSaveOptions();options.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsPngImagesEmbeddedIntoSvg;//<- to get compatibility with previous behavior and therefore same result of tests// 将 HTML输出分成页面options.SplitIntoPages = true;// 将 CSS分成页面options.SplitCssIntoPages = true;options.CustomCssSavingStrategy = new HtmlSaveOptions.CssSavingStrategy(Strategy_4_CSS_MULTIPAGE_SAVING_RIGHT_WAY);options.CustomStrategyOfCssUrlCreation = new HtmlSaveOptions.CssUrlMakingStrategy(Strategy_5_CSS_MAKING_CUSTOM_URL_FOR_MULTIPAGING);// 4)进行转换pdfDocument.Save(htmlFile, options);
private static void Strategy_4_CSS_MULTIPAGE_SAVING_RIGHT_WAY(HtmlSaveOptions.CssSavingInfo partSavingInfo){    string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();    string outPath = dataDir + "style_xyz_page" + partSavingInfo.CssNumber.ToString() + ".css";    System.IO.BinaryReader reader = new BinaryReader(partSavingInfo.ContentStream);    System.IO.File.WriteAllBytes(outPath, reader.ReadBytes((int)partSavingInfo.ContentStream.Length));}private static string Strategy_5_CSS_MAKING_CUSTOM_URL_FOR_MULTIPAGING(HtmlSaveOptions.CssUrlRequestInfo requestInfo){    return "/document-viewer/GetCssssId=4544554445_page{0}";}

还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询


如果您对Aspose有任何需求和疑难,记得扫描下方二维码告诉我们哦~

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月27日
下一篇 2019年9月27日

相关推荐

发表回复

登录后才能评论