0

it's should be simple but i couldn't find the answer anywhere in google or the source documentation.

someone have asked the same question 4 years ago, but still no one answered!

if it's not possible. can someone please confirm, so that i can find another pdf generator library that can do that. because it's very important in my case to be able to generate pdf with input capability

thanks!

2 Answers2

-1

See my post here with Links on how to to add text to an existing field and also how to add a field to a PDF document using PDFsharp.

Coden
  • 2,579
  • 1
  • 18
  • 25
-6

We will go through the step by step

  1. First you need to create object of PdfReader
    • PdfReader pdfReader = new PdfReader(templatePath); here "templatePath" is the template(sample file) where you write your all data
  2. Then create source file where all data is rendered(write)
    • System.IO.Directory.CreateDirectory(Server.MapPath(DocPath)); "DocPath" is the path where output file is save
  3. Then Initialize PdfStamper and AcroFields object :

    PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(Server.MapPath(newFile), FileMode.Create));
    AcroFields pdfFormFields = pdfStamper.AcroFields;
    
  4. Then set Field in PDF :

        pdfFormFields.SetField("this text should field name in PDF(template PDF)", "Actual value you want to write");
    
  5. Dispose all objects

        pdfStamper.FormFlattening = true;
        pdfStamper.Close();
        pdfReader.Close();