首页 > Windows开发 > 详细

C#使用Pechkin与CPechkin生成PDF

时间:2017-06-07 11:59:22      阅读:1404      评论:0      收藏:0      [点我收藏+]

http://blog.sina.com.cn/s/blog_5a52cec70102wpcf.html

 

 

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();

0

0

C#使用Pechkin与CPechkin生成PDF

原文:http://www.cnblogs.com/wdcwy/p/6956102.html

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