zoukankan      html  css  js  c++  java
  • 使用Pechkin与CPechkin生成PDF

    1. Pechkin
        从NuGet程序管理器中获得Pechkin,代码示例如下:
                GlobalConfig config = new GlobalConfig();
                SimplePechkin pechkin = new SimplePechkin(config);
                ObjectConfig objectConfig = new ObjectConfig();
                objectConfig.SetPrintBackground(true)
                    .SetLoadImages(true)
                    .SetAffectPageCounts(true)
                    .SetPageUri("http://www.abc.com/");//此处替换为你的uri
                byte[] bytePDF = pechkin.Convert(objectConfig);//此处亦支持html字符串
                File.WriteAllBytes("F:\PDFName.pdf", bytePDF);
    2. CPechkin
        使用Pechkin不能合并多个uri为一个PDF,故引入CPechkin,获得方式与Pechkin同,代码示例如下:
                SynchronizedPechkin sc = new SynchronizedPechkin(
                    new GlobalConfig()
                    .SetMargins(new Margins(100, 100, 100, 100))
                    );
                IList uris = new List
                {
                new Uri(@"http://www.a.com/"),
                new Uri(@"http://www.b.com/")
                };
                byte[] buf = sc.Convert(uris);
                string fn = @"F:PDFName.pdf";
                FileStream fs = new FileStream(fn, FileMode.Create);
                fs.Write(buf, 0, buf.Length);
                fs.Close();
  • 相关阅读:
    十五周作业
    第十四周总结
    十三周总结与感想
    排球比赛积分规则
    Centos + nginx + JBOSS AS 7 搭建Java web application
    eclipse + maven + jboss 遇到ClassNotFoundException
    “/”应用程序中的服务器错误。 纠错方法
    Sharepoint 问题集锦
    Sharepoint 问题集锦
    Sharepoint 问题集锦
  • 原文地址:https://www.cnblogs.com/xuejietong/p/8902082.html
Copyright © 2011-2022 走看看