C# PDF操作之-PDF转HTML
特别说明:需引用Aspose.PDF.dll
代码案例:
using System.IO;
using System;
using Aspose.Pdf;namespace Aspose.Pdf.Examples.CSharp.AsposePDF.DocumentConversion
{public class PDFToHTML{public static void Run(){// ExStart:PDFToHTML// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();// Open the source PDF documentDocument pdfDocument = new Document(dataDir + "PDFToHTML.pdf");// Save the file into MS document formatpdfDocument.Save(dataDir + "output_out.html", SaveFormat.Html);// ExEnd:PDFToHTML}public static void ExcludeFontResources(){// ExStart:ExcludeFontResources// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();string inFile = dataDir + "PDFToHTML.pdf";string outMainHtmlFile = dataDir + "ExcludeFontResources.pdf";// Initialize htmlOptionsHtmlSaveOptions htmlOptions = new HtmlSaveOptions{ExplicitListOfSavedPages = new[] { 1 },FixedLayout = true,CompressSvgGraphicsIfAny = false,SaveTransparentTexts = true,SaveShadowedTextsAsTransparentTexts = true,//FontSavingMode = HtmlSaveOptions.FontSavingModes.DontSave,ExcludeFontNameList = new[] { "ArialMT", "SymbolMT" },DefaultFontName = "Comic Sans MS",UseZOrder = true,LettersPositioningMethod = HtmlSaveOptions.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss,PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.NoEmbedding,RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground,SplitIntoPages = false};Document pdfDocument = new Document(inFile);// SavepdfDocument.Save(outMainHtmlFile, htmlOptions);// ExEnd:ExcludeFontResources}public static void MultiPageHTML(){// ExStart:MultiPageHTML// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();// Open the source PDF documentDocument pdfDocument = new Document(dataDir + "PDFToHTML.pdf");// Instantiate HTML SaveOptions objectHtmlSaveOptions htmlOptions = new HtmlSaveOptions();// Specify to split the output into multiple pageshtmlOptions.SplitIntoPages = true;// Save the documentpdfDocument.Save(@"MultiPageHTML_out.html", htmlOptions);// ExEnd:MultiPageHTML}public static void SaveSVGFiles(){// ExStart:SaveSVGFiles// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();// Load the PDF fileDocument doc = new Document(dataDir + "PDFToHTML.pdf");// Instantiate HTML save options objectHtmlSaveOptions newOptions = new HtmlSaveOptions();// Specify the folder where SVG images are saved during PDF to HTML conversionnewOptions.SpecialFolderForSvgImages = dataDir;// Save the output filedoc.Save(dataDir + "SaveSVGFiles_out.html", newOptions);// ExEnd:SaveSVGFiles}public static void CompressSVGImages(){// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();// Load the PDF fileDocument doc = new Document(dataDir + "PDFToHTML.pdf");// ExStart:CompressSVGImages// Create HtmlSaveOption with tested featureHtmlSaveOptions newOptions = new HtmlSaveOptions();// Compress the SVG images if there are anynewOptions.CompressSvgGraphicsIfAny = true;// ExEnd:CompressSVGImages// Save the output filedoc.Save(dataDir + "CompressSVGImages_out.html", newOptions);}public static void SpecifyingImageFolder(){// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();// Load the PDF fileDocument doc = new Document(dataDir + "PDFToHTML.pdf");// ExStart:SpecifyingImageFolder// Create HtmlSaveOption with tested featureHtmlSaveOptions newOptions = new HtmlSaveOptions();// Specify the separate folder to save imagesnewOptions.SpecialFolderForAllImages = dataDir;// ExEnd:SpecifyingImageFolder// Save the output filedoc.Save(dataDir + "SpecifyingImageFolder_out.html", newOptions);}public static void CreateSubsequentFiles(){// ExStart:CreateSubsequentFiles// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();Document doc = new Document(dataDir + "PDFToHTML.pdf");HtmlSaveOptions options = new HtmlSaveOptions();// This is the tested settingoptions.HtmlMarkupGenerationMode = HtmlSaveOptions.HtmlMarkupGenerationModes.WriteOnlyBodyContent;options.SplitIntoPages = true;doc.Save(dataDir + "CreateSubsequentFiles_out.html", options);// ExEnd:CreateSubsequentFiles}public static void TransparentTextRendering(){// ExStart:TransparentTextRendering// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();Document doc = new Document(dataDir + "PDFToHTML.pdf");HtmlSaveOptions htmlOptions = new HtmlSaveOptions();htmlOptions.SaveShadowedTextsAsTransparentTexts = true;htmlOptions.SaveTransparentTexts = true;doc.Save(dataDir + "TransparentTextRendering_out.html", htmlOptions);// ExEnd:TransparentTextRendering}public static void LayersRendering(){// ExStart:LayersRendering// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();Document doc = new Document(dataDir + "PDFToHTML.pdf");// Instantiate HTML SaveOptions objectHtmlSaveOptions htmlOptions = new HtmlSaveOptions();// Specify to render PDF document layers separately in output HTMLhtmlOptions.ConvertMarkedContentToLayers = true;// Save the documentdoc.Save(dataDir + "LayersRendering_out.html", htmlOptions);// ExEnd:LayersRendering}public static void CreatingHtmlWithFullContentWidth(){//ExStart: CreatingHtmlWithFullContentWidth// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();HtmlSaveOptions saveOptions = new HtmlSaveOptions();saveOptions.FixedLayout = (false);saveOptions.FlowLayoutParagraphFullWidth = true;Document doc = new Document(dataDir + "FlowLayoutParagraphFullWidth.Pdf");doc.Save(dataDir + "FlowLayoutParagraphFullWidth_out.html", saveOptions);//ExEnd: CreatingHtmlWithFullContentWidth}public static void CenterAlignText(){//ExStart: CenterAlignTextHtmlSaveOptions htmlOptions = new HtmlSaveOptions();// init MarginPartStyle with margin in 20 pointsvar commonMargin = new SaveOptions.MarginPartStyle(20);// init MarginPartStyle with margin value autovar autoMargin = new SaveOptions.MarginPartStyle(true);// set commonMargin to every page sidehtmlOptions.PageMarginIfAny = new HtmlSaveOptions.MarginInfo(commonMargin);// set horizontal page align to centerhtmlOptions.PageMarginIfAny.LeftMarginIfAny = autoMargin;htmlOptions.PageMarginIfAny.RightMarginIfAny = autoMargin;//ExEnd: CenterAlignText}}
}
C# PDF操作之-PDF转HTML相关推荐
- C# PDF操作之-PDF转TXT
特别说明:需引用Aspose.PDF.dll 代码案例: using System.IO; using Aspose.Pdf; using Aspose.Pdf.Text; using System; ...
- C# PDF操作之-PDF转PPT
特别说明:需引用Aspose.PDF.dll 代码案例: using System; using System.IO; using Aspose.Pdf;namespace Aspose.Pdf.Ex ...
- C# PDF操作之-PDF转EXCEL
特别说明:需引用Aspose.PDF.dll 代码案例: OpenFileDialog openFileDialog1 = new OpenFileDialog(); //显示选择文件对话框 open ...
- Linux下PDF操作与转换
Linux下PDF操作与转换 2013-07-02 09:44:58 分类: LINUX 如果说PDF是电子纸张,那么pdftk就是电子起钉器.打孔机.粘合剂.解密指环和 X光镜片.Pdftk是一个简 ...
- 打造全键盘操作的PDF阅读器
其实我只想要一个非常简单的PDF阅读器,不要很花哨的功能,只要能够: 速度够快,不要翻一页等半天: 全键盘操作,不想在鼠标和键盘之间来回倒腾: 可以改变背景色,深夜的白光好刺眼: 自由旋转页面,有些P ...
- Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案
Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案 参考文章: (1)Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案 (2)ht ...
- 【报告分享】万达文旅项目新媒体营销操作手册.pdf(附下载链接)
今天给大家分享的报告是万达文旅的<万达文旅项目新媒体营销操作手册.pdf>,需要搭建新媒体营销团队及方案的朋友们可以参考下,手册共包含如下七大部分: 1.新媒体营销操作手册目标: 2.新媒 ...
- 大多数人不敢想的PDF操作:添加书签,电子签名,压缩,修改文字,提取部分页面为新文件、批量导出为图片
目录 PDF神仙级软件和网站(免费) PDF加书签 PDF电子签名 PDF文件压缩 修改PDF内的文字 提取部分页面为新PDF文件 PDF批量导出为图片 PDF神仙级软件和网站(免费) 主要以比较方便 ...
- 免费离线PDF工具箱,PDF工具大全,PDF合并PDF加密PDF解密PDF格式转换PDF分割PDF旋转以及从PDF中提取图片,满足对PDF操作的一切需求~完全免费无使用次数限制,文末附下载链接~
一款 完全免费 的PDF工具箱,软件一共 内置45个和PDF文件操作相关的功能,无需注册登录 即可 免费使用,所有的功能都 不限制使用次数,你对PDF操作的大多数需求它都能满足!而且 所有操作均在本地 ...
最新文章
- 史上最大规模 DDoS 攻击,每秒 1720 万次 HTTP 请求
- mysql 缓存监控_MySQL监控性能的一些方法总结
- 计算机应用基础任务化教程知识点,计算机应用基础任务化教程
- 公众号点击图片变成另一张_微信公众号点击出现图片是怎么实现的?
- 晶创6电梯卡的数据结构_修改电梯卡发现“商机”,男子涉嫌盗窃罪!
- 【bzoj2406】矩阵 二分+有上下界可行流
- Careercup - Microsoft面试题 - 5680049562845184
- Java的对象序列化之serialVersionUID问题
- Sublime Text新增GBK编码支持
- 如何在计算机设置鼠标宏,鼠标宏怎么设置,教您鼠标如何设置宏
- 福州到横店嘉兴三日游(仅供参考)
- rk3288 linux 编译,RK3288系统编译及环境搭建
- latex 表格标题分行和居中
- 知识点3-设计模式与实践
- BUUCTF RE WP31-32 [WUSTCTF2020]level1、[GWCTF 2019]xxor
- 3dsmax网格重构细分
- 量子信息与量子计算_我们会看到量子计算革命吗?
- *6-3 节约小能手
- linux进程网络监控,linux下的进程、网络、性能监控命令
- 深入理解Android之Gradle