用于生成pdf的C#代码中不显示数据 [英] No display of data in the C# code for pdf generation

查看:68
本文介绍了用于生成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();
       }

推荐答案

试试这个...... :)





使用C#生成PDF [ ^ ]
try this...:)


Generate PDF Using C#[^]


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆