I'm using Apache PDFBox to populate an existing Adobe Acrobat PDF template.
In this template I have fixed sizes of text fields in which I insert data from database.
In one text field the amount of data may vary so it would be great if text field could get bigger or smaller to adjust to the amount of text inserted.
The main problem is that I have another text fields below the one I want to resize dynamically so in case of making it bigger or smaller other text fields have to move relatively
I was searching for the solution but found only offers to resize font dynamically, but it doesn't satisfy my needs. I could create one text field and insert all of my data in it, but some of those text fields must have different color of text so it's important to have different text fields to be able to specify their color in code (as far as I know).
Is that even possible and if not what can I do to achieve the result I'm looking for?
P.S. Our code is based on templates from Adobe Acrobat and Apache PDFBox, so it's more preferable to keep it that way. But if this is not possible with those two, I will be glad to hear your recommendations on what should I use (open source first).
PDF Producer: Adobe Acrobat Pro DC (32-bit) 21.7.20102,
PDF Version: 1.6 (Acrobat 7.x),
Apache PDFBox Version: 2.0.26
You can find an example of my PDF below
I'm using itext 7 to fill dynamic xfa form. I tried example provided in itext website which work for static part of PDF but dynamic part so not displaying on render filled PDF.
The PDF have an add button, on clicking add button few fields appears. This fields are not displaying even when values for this fields are filled. Can anyone suggest any approach to solve this problem.
I have a problem with iText and flatten form fields in pdfs.
I submit a pdf with form fields created in Acrobat to my java method. On a website i have created a form to fill the form fields in the pdf. The form fields are filled correctly, but as soon as i flatten the document the text is moved to a little different position. The biggest difference is seen in multiline form fields. There the text is at the border of the field in the upper left. In Acrobat and before flattening the text has a padding to the top.
Here is my java code to call the methods of iText:
PdfReader template = new PdfReader(templ);
XfdfReader xfdfReader = new XfdfReader(xfdf);
OutputStream outputStream = new FileOutputStream(output);
PdfStamper stamper = new PdfStamper(template, outputStream, '\0');
AcroFields form = stamper.getAcroFields();
Set<String> fields = form.getFields().keySet();
form.setFields(xfdfReader);
stamper.setFreeTextFlattening(true);
stamper.setFormFlattening(true);
stamper.close();
template.close();
Anyone has an idea why the text is moving when i flatten the pdf? How can I avoid this?
I allready tried different versions from iText. From version 4.X to 5.X. The difference appears in all versions.
Although i tried to move the form fields in the code of iText, but then the whole field is moving and the difference of the position is much bigger and not predictable.
In my project the text must be at the exact same position as in Acrobat, so i must find a workaround for this misbehavior. I hope somebody can help me.
Thanks for your help in advance.
The position of the baseline of a field in a PDF file has been changed over the years. You'll even see differences depending on the version of Acrobat you are using.
There is no solution for your problem unless you know the exact offset. If you do, you can use the setExtraMargin() method to change the offset of all fields when flattening the document.
We created this method to deal with specific forms that have a baseline that is different from what is to be expected. Which values you choose can be different for different forms.
In my application I have to fill a predefined PDF form with data from DB. We are using Java and Pdfbox. The filling itself is not a problem.
The problem is that in resulting PDF-file all texts in the form are invisible (or hidden, also grey rectangles) unless field clicked.
How can I solve this problem?
I had the same problem when I tried to programmatically fill PDF forms using pdfbox. I add this answer to a rather old question as all the other answers manipulate the original PDF, which is not always an option.
The problem with invisible form fields just appeared in Acrobat PDF, other PDF renderers showed it fine. If using pdfbox 1.8.x you have to set Need Appearances as explained here:
PDAcroForm form = docCatalog.getAcroForm();
form.getDictionary().setItem(COSName.getPDFName("NeedAppearances"), COSBoolean.TRUE);
If using pdfbox 2 this is simplified to:
PDAcroForm form = docCatalog.getAcroForm();
form.setNeedAppearances(true);
I read this on a forum and worked for me:
Using Adobe Acrobat Pro, I exported the form using "Export Data" to a XML and then imported it back from XML-file with "Import Data". Those commands are under Forms/Manage Forms Data
This is the link to the post: http://forums.adobe.com/thread/637421
I had this exact problem with a form I was filling with PDFBox in Java.
I fixed it by opening the original (blank) PDF form in Acrobat Pro and changing some options for each of the problem text fields. The options might vary for you, but here's what worked for me:
In the Acrobat Pro menu bar go to Forms > Add or edit fields.
Right click the text field in Acrobat Pro and select properties, then:
In the 'Options' tab:
Untick all options except 'scroll long text'
Add a few space characters in to the Default Value box
In the 'Appearance' tab:
Set the font size to 'auto'
Click 'close form editing' and save the file.
I just ran across this and tried a combination of things before one very simple thing worked. I have Adobe Acrobat 9.0 and I couldn't find some of the options written here.
What I ended up doing was a two-pronged process: I went to Forms > Manage Form Data > Export Data; I then saved that file on my desktop. Next, I went back to Forms > Manage Form Data but instead selected Import Data, and selected that file I'd just saved. Bingo! Everything filled in properly.
I don't quite know how you can stop it happening in the future but a resolution to getting the file working, similar to g-eorge is to open it in adobe acrobat pro, in tools on the right hand menu select "Interactive objects" and choose select object.
When you highlight the first field you want to fix, you should then be able to control-a to select all interactive objects. Once all are selected, right click on one field and select properties.
In the "general" tab the bottom option should have "common properties" which has the option "form field" change this to hidden and then back to visible. This will then restore all visibility to the form.
This has worked for me on all the rare instances when I receive this, and hasn't failed me once. Hope it does the same for you,
BoB
in the appearance tab of each erroneously hidden object you will see the "fill color" set to none. set it to none again (just click on it) and save the PDF and these fields will show up normally. I can't believe adobe has let this error persist for so long. It happens constantly when viewing/saving with multiple pdf readers.
Nothing I tried here worked - except to change software.
I was using PDFElement 6 Pro (trial) and couldn't make it work. Tried all sorts of things with PDFBox plus all suggestions above.
Ended up trying https://www.pdfescape.com/ and it all worked just fine.
In my case I solved it by changing the font to Arial (or one of the standard in windows set), in the 'Appearance' tab, in properties.
Before, it was set Helvetica which was not embedded in the file and that I think generated the problem.
I'm trying to edit a existing PDF file. It is a file where I need to fill in some addresses and other stuff. I want to connect an addressbook to the application so the user can select a user from the addressbook and a part get filled in automatic.
My questions are:
Is it possible to edit a existing PDF file and fill in some fields (+/- 20), because I know there is Itext (http://www.itextpdf.com) but I read that the possiblities are very small.
Or can I better convert the PDF to JPG and get it as background. And create JLabels on the places where I need to fill in the fields. And then print the whole Frame on a A4.
Or are there better posibilities?
So what I need to do, step by step:
Select one of the PDF's (they are in the program)
Fill some fields with content/addresses
Print the PDF/Form with a printer
There is a toolkit given by Adobe named as Acrobat Forms Data Format (FDF) Toolkit which gives API for different languages to fill forms.
You can get the java code at the bottom of that page or check this link
We didn't edit existing PDF's but created totally new letters/reports/doco from our java app using iReport
You could use pdf form and edit field values programmatically using IText or Apache PDFBox (download pdfbox and see SetField.java example)