zoukankan      html  css  js  c++  java
  • html 网页生产pdf文件

    在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:	emp20160602	est.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();
            }
        }
    }
  • 相关阅读:
    从尾到头打印链表
    在链表结尾插入一个结点 以及在 在链表中找到第一个含有某值的结点并删除该结点
    替换空格
    二维数组中的查找
    简单选择排序
    冒泡排序
    Hash表的实现
    二叉排序树
    ajax返回后台编译时都对,返回error
    sql删除重复的记录保留一条
  • 原文地址:https://www.cnblogs.com/weiweictgu/p/6935634.html
Copyright © 2011-2022 走看看