pdf转html,pdf转word等 电脑版发表于:2019/5/18 21:19 #### 方法一:使用Aspose.Words转 这种方法效果不是太好,毕竟Aspose.Words,主要是做word相关转换的。比如word转pdf,word转html这个库还是非常强大的 ``` public void PdfTOHtml() { string dir = _webHostEnvironment.ContentRootPath; PdfDocumentReaderPlugin pdfDocumentReaderPlugin = new PdfDocumentReaderPlugin(); FileStream fileStream = new FileStream(dir + "/words/allin.pdf", FileMode.Open); Aspose.Words.Loading.LoadOptions loadOptions = new Aspose.Words.Loading.LoadOptions(); Aspose.Words.Document document = new Aspose.Words.Document(); pdfDocumentReaderPlugin.Read(fileStream, loadOptions, document); //这样目录位置是项目根目录 //document.Save("xx.docx"); HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions(); //htmlSaveOptions.ImageResolution = 100; //为false图片以原生大小输出,看注释里边有就是注释太长了难得找 htmlSaveOptions.ScaleImageToShapeSize = false; //wrdf.Save(dir + "/words/xss.html", Aspose.Words.SaveFormat.Html); document.Save(dir + "/words/html/xss.html", htmlSaveOptions); } ``` #### 方法二:使用Aspose.Pdf转 这种方法效果就好了,毕竟是本专业 ``` public void PdfToHTmlByAsposePdf() { string dir = _webHostEnvironment.ContentRootPath; string dataDir = dir + "/words/allin.pdf"; // 源PDF文件 Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir); //使用测试的功能创建HtmlSaveOption Aspose.Pdf.HtmlSaveOptions saveOptions = new Aspose.Pdf.HtmlSaveOptions(); saveOptions.FixedLayout = true; saveOptions.SplitIntoPages = false; saveOptions.RasterImagesSavingMode = Aspose.Pdf.HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg; //将输出保存为HTML格式 doc.Save(dataDir + "SaveImages_out.html", saveOptions); //doc.Save(dir + "/words/html/xss.html",Aspose.Pdf.SaveFormat.Html); } ```