首页 > Web开发 > 详细

Aspose.Pdf pdf转Html,并设置保存路径,图片路径

时间:2018-08-14 16:36:59      阅读:281      评论:0      收藏:0      [点我收藏+]
using System.IO;
using System.Text;
using Aspose.Pdf;

namespace System.Extensions
{
    public static class PdfConverter
    {
        public static string Read(Stream stream, string fullPath)
        {
            if (Directory.Exists(fullPath))
            {
                Directory.Delete(fullPath, true);
            }
            Directory.CreateDirectory(fullPath);
            try
            {
                var doc = new Document(stream);
                var saveOptions = new HtmlSaveOptions()
                {
                    FixedLayout = true,
                    SplitIntoPages = false,
                    SplitCssIntoPages = false,
                    RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground,
                    SpecialFolderForAllImages = fullPath
                };
                var path = Path.Combine(fullPath, "i.html");
                doc.Save(path, saveOptions);
                string html;
                using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    var reader = new StreamReader(fileStream, Encoding.UTF8);
                    html = reader.ReadToEnd();
                    reader.Close();
                }
                File.Delete(path);
                return html;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
}

 

Aspose.Pdf pdf转Html,并设置保存路径,图片路径

原文:https://www.cnblogs.com/microfac/p/9475363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!