-1

I have pdf with bytes i am reading that pdf with

byte[] pdfContent =[];

PdfReader pdfReader = new PdfReader(pdfContent); 

using (MemoryStream outputStream = new MemoryStream())
{
    using (var pdfStamper = new PdfStamper(pdfReader, outputStream))
    {
        AcroFields pdfFormFields = pdfStamper.AcroFields;
        pdfFormFields .SetField("txtForename", "Test"));
        pdfStamper.Close();
        array = outputStream.ToArray();
    }
}

How to download this edit pdf with memorystream

trailmax
  • 34,305
  • 22
  • 140
  • 234
Meena
  • 169
  • 1
  • 9

1 Answers1

0

First of all your code is seems wrong. You have empty PdfContent and you are you are trying to open pdf with empty content I guess. Furthermore, you dont need MemoryStream because your intention will be to write your file to disk (filestream would be your best option for this)

this example can help you on editing your pdf.

private void fillPDFForm()
{
    string formFile = Server.MapPath(P_InputStream);
    string newFile = Server.MapPath(P_OutputStream);
    PdfReader reader = new PdfReader(formFile);
    using (PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Create)))
    {
        AcroFields fields = stamper.AcroFields;

        // set form fields
        fields.SetField("name", "John Doe");
        fields.SetField("address", "xxxxx, yyyy");
        fields.SetField("postal_code", "12345");
        fields.SetField("email", "johndoe@xxx.com");

        // flatten form fields and close document
        stamper.FormFlattening = true;
        stamper.Close();
    }
}

further reference: https://simpledotnetsolutions.wordpress.com/2012/04/08/itextsharp-few-c-examples/

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • Here i am not able to get the edited pdf , in that path pdf was empty not able to see what i edited in pdf – Meena Dec 04 '18 at 09:38
  • without placing that document in path can we download like if we download anything from internet we can see that in browser history download path are default path – Meena Dec 04 '18 at 09:49