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生成

猜你喜欢

转载自www.cnblogs.com/TRMan/p/11414157.html