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

posted on 2018-05-12 11:04  庭前花满留晚照  阅读(847)  评论(0编辑  收藏  举报

导航