码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-08-14 17:02:48      阅读:583      评论:0      收藏:0      [点我收藏+]

标签:sys   style   creat   split   try   share   ast   created   OLE   

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,并设置保存路径,图片路径

标签:sys   style   creat   split   try   share   ast   created   OLE   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!