0
我正在使用iTextSharp從文件路徑讀取pdf文件,在瀏覽器中編輯並打開文件。server.mappath中的相對路徑
當我在本地運行它時,下面的代碼工作正常。在我發佈並託管它之後,我無法從文件路徑中讀取該文件。我認爲我在相對路徑上犯了一些錯誤。
string path = System.Web.HttpContext.Current.Server.MapPath("~/Doc/template.pdf");
請幫幫我。
using iTextSharp.text.pdf;
private void GeneratePDF()
{
byte[] bytes = null;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
string path = System.Web.HttpContext.Current.Server.MapPath("~/Doc/template.pdf");
// Create the form filler
using (PdfReader pdfReader = new PdfReader(path))
{
using (PdfStamper pdfStamper = new PdfStamper(pdfReader, ms))
{
StringBuilder sbstring = null;
// Get the form fields
AcroFields testForm = pdfStamper.AcroFields;
....
....
PdfContentByte overContent = pdfStamper.GetOverContent(1);
pdfStamper.FormFlattening = true;
}
}
bytes = ms.ToArray();
}
//Writes it back to the client
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" +
sbFileName.ToString() + "");
Response.BinaryWrite(bytes);
}
}
您是否收到錯誤消息? –