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

html 网页生产pdf文件

时间:2017-06-03 00:56:28      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:htm   rip   gen   create   obj   using   text   dia   lin   

在nuget中安装组件 

Install-Package CPechkin

 

https://www.nuget.org/packages/CPechkin/

根据html生产pdf文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Pechkin.Synchronized;
using Pechkin;
using System.Drawing.Printing;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //string fileName = Path.GetTempFileName();
            //using (FileStream fs = new FileStream(fileName,FileMode.OpenOrCreate))
            //{
            //    using (StreamWriter sw = new StreamWriter(fs))
            //    {
            //        sw.WriteLine(Guid.NewGuid());
            //    }
            //    //sw.Flush();
            //    //fs.Close();
            //}
            //var fileExists = File.Exists(fileName);
            //using (StreamReader sr = new StreamReader(fileName))
            //{
            //    string res = sr.ReadLine();
            //}

            SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig().SetMargins(new Margins(100, 100, 100, 100)));
            ObjectConfig oc = new ObjectConfig();
            oc.SetPrintBackground(true).SetRunJavascript(true).SetScreenMediaType(true)
              .SetLoadImages(true)
              .SetPageUri("http://www.baidu.com");

            IList<Uri> uris = new List<Uri>

{

new Uri(@"http://www.baidu.com"),

new Uri(@"E:\temp\20160602\test.html")

};

            byte[] buf = sc.Convert(uris);

            string fn = Path.GetTempFileName() + ".pdf";

            FileStream fs = new FileStream(fn, FileMode.Create);

            fs.Write(buf, 0, buf.Length);

            fs.Close();
        }
    }
}

 

html 网页生产pdf文件

标签:htm   rip   gen   create   obj   using   text   dia   lin   

原文地址:http://www.cnblogs.com/weiweictgu/p/6935634.html

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