我想在程序生成 PDF 后打开它。我知道它已经在互联网上得到了解答,但我找不到可以解决我的问题的令人满意的答案。这是我生成 PDF 时的代码。 protected void btnPdf_Click(object sender, EventArgs e){ GridViewRow rows = TraineeGrid.SelectedRow; Label varName = (Label)rows.FindControl("lbName"); string name = varName.Text; Label varCourse = (Label)rows.FindControl("lbCourse"); string course = varCourse.Text; Label varCertNum = (Label)rows.FindControl("lbCertNum"); string certNumber = varCertNum.Text; Label varEndDate = (Label)rows.FindControl("lbEndDate"); string endDate = varEndDate.Text; DateTime date = DateTime.Parse(endDate); string finalEDate = date.ToString("MMMM dd, yyyy"); Label varStartDate = (Label)rows.FindControl("lbStartDate"); string startDate = varStartDate.Text; DateTime date1 = DateTime.Parse(startDate); string finalSDate = date1.ToString("MMMM dd, yyyy"); try { string inputCertificate = "D:\\Intern\\BASSWeb\\Certificates\\InitialCertificate.pdf"; string outputCertificate = "D:\\Intern\\BASSWeb\\Certificates\\" + course + "_" + name + ".pdf"; string newFileName = getNextFileName(outputCertificate); // open the reader PdfReader reader = new PdfReader(inputCertificate); Rectangle size = reader.GetPageSizeWithRotation(1); Document document = new Document(); // open the writer FileStream fs = new FileStream(outputCertificate, FileMode.Create, FileAccess.Write); PdfStamper stamp = new PdfStamper(reader, fs); PdfContentByte cb = stamp.GetOverContent(1); var pageSize = reader.GetPageSize(1); ColumnText ct = new ColumnText(cb); Font font = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 45, iTextSharp.text.Color.BLACK); ct.SetSimpleColumn(28f, 100f, 600f, 305f); Paragraph certText = new Paragraph(new Phrase(20, name, font)); ct.AddElement(certText); ct.Go();我也尝试过,Response.Redirect但仍然没有做任何事情。
1 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
确保关闭 Pdf,然后执行Process.Start(outputCertificate)
.
为此你需要 using System.Diagnostics
另外,我看不出你这样做的原因document.Open();
,那肯定必须关闭才能使用Process.Start();
- 1 回答
- 0 关注
- 179 浏览
添加回答
举报
0/150
提交
取消