asp.net实现输出PDF文件

先引用
在这里插入图片描述

                string doc = "" + PId.Text + "" + "_" + "" + PCarId.Text + "";//文件名
                Document document = new Document();
                PdfWriter.GetInstance(document, new FileStream(Server.MapPath("PDFtemp/" + doc + ".pdf"), FileMode.Create));
                document.Open();
                BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL);


                //输出图片到PDF文件 
                iTextSharp.text.Image jpeg01 = iTextSharp.text.Image.GetInstance(Server.MapPath("images/a1.png"));
                document.Add(jpeg01);
                
                string ss1 = "编号:" + PId.Text + "  机关:" + Pinstitution.Text + " 证件号:" + PCarId.Text + "";
                string ss2 = "被罚人:" + Pname.Text + "";              
                string txt = "" + ss1 + "" + Environment.NewLine + "" + ss2 + "" ;
                //所输的内容按设置的字体到PDF文件
                document.Add(new Paragraph(txt, fontChinese));
                document.Close();
                Response.Write("<script>alert('导出成功!');</script>");

版权声明:本文为H_aspx原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。