我使用itextsharp创建一个PDF文件。它已成功创建并使用adobe reader 9打开,而不是adobe reader 7和8.请帮我修复此错误。
这是我的部分代码:
try
{
//yourFont = BaseFont.CreateFont(Application.StartupPath + "/verdana.TTF", BaseFont.WINANSI, BaseFont.EMBEDDED);
pgSize = new iTextSharp.text.Rectangle(320, 455);
doc = new Document(pgSize, 15, 5, 12, 4);
fnt = new iTextSharp.text.Font(yourFont, 7, 3);
fnt1 = new iTextSharp.text.Font(yourFont, 5, 0);
fnt2 = new iTextSharp.text.Font(yourFont, 3, 2);
fnt3 = new iTextSharp.text.Font(yourFont, 4, 6);
PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("Payslip.pdf"), FileMode.Create));
//PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("Payslip.pdf"), FileMode.Create)); //Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Payslip.pdf"
doc.Open();
DataView DView = (DataView)Session["data_value"];
dtData = DView.ToTable();
dr = dtData.Select("fldemp_no='" + Session["EmployeeID"].ToString() + "'");
doc.NewPage();
iTextSharp.text.Image ObjImg = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Bin/Head.png"));
ObjImg.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
ObjImg.ScaleToFit(220f, 150f);
ObjImg.SpacingBefore = 13f;
ObjImg.SpacingAfter = 1f;
doc.Add(ObjImg);
maintable = new PdfPTable(1);
cell = new PdfPCell(new Phrase("Pay Slip for the month of " + dr[0]["fldmonth"].ToString(), fnt1));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.Border = 0;
maintable.AddCell(cell);
doc.Add(maintable);
maintable = new PdfPTable(2);
empdetright = new PdfPTable(2);
empdetleft = new PdfPTable(2);
cell = new PdfPCell(new Phrase("Emp No", fnt1));
cell.Border = 0;
empdetright.AddCell(cell);
cell = new PdfPCell(new Phrase(": " + dr[0]["fldemp_no"].ToString(), fnt1));
cell.Border = 0;
empdetright.AddCell(cell);
cell = new PdfPCell(new Phrase("Emp Name", fnt1));
cell.Border = 0;
empdetright.AddCell(cell);
cell = new PdfPCell(new Phrase(": " + dr[0]["fldempname"].ToString(), fnt1));
cell.Border = 0;
empdetright.AddCell(cell);
.......
doc.Close();
Process.Start(Server.MapPath("Payslip.pdf"));
以上代码在不在服务器上的本地计算机上运行。请帮我解决这个错误。
答案 0 :(得分:0)
Process.Start
将尝试在其运行的计算机(服务器)中打开该文件。
这不太可能是你想要的。您应该将文件上传到浏览器并让它决定(例如,使用Response.WriteFile
)。