用于生成pdf的C#代码中不显示数据

用于生成pdf的C#代码中不显示数据

本文介绍了用于生成pdf的C#代码中不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public string HTMLToPdf(_TableProperty ReportProperty, string FilePath,Stream stream)
       {
           string htmlread2 = getReportHTML(ReportProperty, stream);
           Document document = new Document();
           PdfWriter.GetInstance(document, new FileStream(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "C:\\HRMS OSN\\latest\\HRMS\\admpanel\\myPDF.pdf", FileMode.Create));
           document.Open();
           iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("pdfic.jpg"));

           pdfImage.ScaleToFit(100, 50);

           pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760);

           document.Add(pdfImage);
           iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
           iTextSharp.text.html.simpleparser.XHTMLWorker hw = new iTextSharp.text.html.simpleparser.XHTMLWorker(document);
           hw.Parse(new StringReader(htmlread2));
           document.Close();
           ShowPdf("C:\\HRMS OSN\\latest\\HRMS\\admpanel\\myPDF.pdf");
           return htmlread2;
       }

       private void ShowPdf(string s)
       {
           System.Web.HttpContext.Current.Response.ClearContent();
           System.Web.HttpContext.Current.Response.ClearHeaders();
           System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + s);
           System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
           System.Web.HttpContext.Current.Response.WriteFile(s);
           System.Web.HttpContext.Current.Response.Flush();
           System.Web.HttpContext.Current.Response.Clear();
       }

推荐答案


这篇关于用于生成pdf的C#代码中不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:18