我想在程序生成 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但仍然没有做任何事情。
12345678_0001
相关分类