我使用itextsharp創建一個PDF文件。它已成功創建,並使用adobe reader 9打開,而不是在adobe reader 7和8中。請幫我解決這個錯誤。Process.start不能在服務器上工作
這是我的部分代碼:
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"));
上面的代碼是在本地機器上沒有在服務器上運行。請幫我解決這個錯誤..
標題似乎與您擁有的問題無關,似乎是您通過iTextSharp生成了PDF,但它只能在Reader 9中打開,而不是在Reader 7或8中打開。這是正確的嗎? – MartW