问题
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!
回答1:
We will go through the step by step
- 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
- 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
Then Initialize PdfStamper and AcroFields object :
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(Server.MapPath(newFile), FileMode.Create)); AcroFields pdfFormFields = pdfStamper.AcroFields;
Then set Field in PDF :
pdfFormFields.SetField("this text should field name in PDF(template PDF)", "Actual value you want to write");
Dispose all objects
pdfStamper.FormFlattening = true; pdfStamper.Close(); pdfReader.Close();
来源:https://stackoverflow.com/questions/52717558/how-to-add-input-text-field-to-pdf-acroform-with-pdfsharp