I have a pdf with a form. I am trying to write a class that will receive data from my database and automatically fill in the fields on the form.
I already tried ITextSharp, and their price is not in my budget, although it works fine with my pdf. I need a free PDF parser that will allow me to import a PDF file, set the data and save the PDF file, preferably to a stream, so that I can return the Stream object from my class, and not save the pdf file to the server.
I found this PDF reader and it does not work. Zero link errors are plentiful, and when I tried to “fix” them, he still could not find my fields.
So, I switched to PdfBox, as the documentation says that it can manipulate PDF, however I can not find examples. Here is the code I have.
var document = PDDocument.load(inputPdf);
var catalog = document.getDocumentCatalog();
var form = catalog.getAcroForm();
form.getField("MY_FIELD").setValue("Test Value");
document.save("some location on my hard drive");
document.close();
The problem is that it catalog.getAcroForm()returns null, so I cannot access the fields. Does anyone know how I can use PdfBox to change field values and save this information?
EDIT:
I found this example , which is pretty much what I am doing. It is just that my acroform is null in pdfbox. I know there is one, because itextsharp can pull it just fine.
source
share