Reputation: 1
I am doing one sample project using iTextSharp (version 5.4.5.0) to fill acrobat fields in PDF template.
After filling acrobat fields, we are not able save the updated PDF template to local path by clicking "SAVE" button on pdf. It is giving error message "The document could not be saved. There was a problem reading this document (26)". Could you please suggest to overcome this error.
public EmptyResult Index(FormCollection form)
{
PdfReader reader = new PdfReader(Server.MapPath(P_InputStream3));
using (MemoryStream ms = new MemoryStream())
{
reader.RemoveUsageRights();
PdfStamper stamper = new PdfStamper(reader,ms);
// Dim stamper As New PdfStamper(reader, New FileStream(sOutputFile, FileMode.Open), Chr(0), True)
AcroFields fields = stamper.AcroFields;
fields.SetField("1_Efternamn", "surya firstname");
fields.SetField("1_Fornamn", "surya lastname");
fields.SetField("pnummer", "1234567890");
fields.SetField("2_anstallning_from", System.DateTime.Now.Date.ToString("yyyyMMdd"));
fields.SetField("2_anstalld_tom", System.DateTime.Now.AddYears(2).Date.ToString("yyyyMMdd"));
fields.SetField("2_chk_ff_anstalld", "true");
fields.SetField("2_arbetsuppgift", "sample test ");
//stamper.FormFlattening = true;2_arbetsuppgift
stamper.Close();
DownloadAsPDF(ms);
reader.Close();
}
return null;
}
private void DownloadAsPDF(MemoryStream ms)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment;filename=certificate.pdf");
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.End();
ms.Close();
}
Upvotes: 0
Views: 4565
Reputation: 11
I FOUND A WORK AROUND! Save As, wasn't working for me Either.
So, after you have made your changes:
Upvotes: 1