C#使用iTextSharp操作PDF文件 简单案例

PdfHelper.cs
try
            {
                string url = "/MedicareVoucher/PDFDetail?oi=" + oi;

                WebClient wc = new WebClient();
                //从网址下载Html字串
                wc.Encoding = Encoding.UTF8;
                //string htmlText = getWebContent();
                string htmlText = wc.DownloadString(url);
                byte[] pdfFile = PdfHelper.ConvertHtmlTextToPDF(htmlText, false);

                return File(pdfFile, "application/pdf", "廊坊市城乡居民基本医疗保险个人缴费凭证.pdf");
            }
            catch (Exception ex)
            {
                return Error(ex.Message);

            }
View 

自动pdf生成

 

posted @ 2019-08-26 18:29  Team_Leading  阅读(597)  评论(0编辑  收藏  举报