I'm using iTextSharp for generation PDF file.Here is the code.
public static byte[] GeneratePDF(string pdfPath, Dictionary<string, string> formFieldMap)
{
var output = new MemoryStream();
var reader = new PdfReader(pdfPath);
var stamper = new PdfStamper(reader, output);
var formFields = stamper.AcroFields;
foreach (var fieldName in formFieldMap.Keys)
{
if (formFieldMap[fieldName] != null)
{
formFields.SetField(fieldName, formFieldMap[fieldName]);
}
}
stamper.FormFlattening = true;
stamper.Close();
reader.Close();
return output.ToArray();
}
Where,
pdfPath - Where to download in Local System.
Dictionary formFieldMap - Having PDF Field Id,Value to show in Field.
In output.ToArray(); I'm getting Values like below.
PDF is downloading, but if I try to open I get "File is Corrupted". Can I get help to resolve this issue?