[
https://issues.apache.org/jira/browse/PDFBOX-3812?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16030722#comment-16030722
]
Maruan Sahyoun commented on PDFBOX-3812:
----------------------------------------
Thanks for offering your help. You could
a) provide a test file with 4 multiline autosize text fields being filled using
Adobe Reader - filled with a single word, filled so the is just before being
autosized, autosized text and text until Adobe Reader stops accepting new input
(it will only scale to a certain limit). 4 more fields being empty with the
same setting so we can use them later to fill the with PDFBox and compare the
result to what Adobe Reader does. Take a look at
/pdfbox/src/test/resources/org/apache/pdfbox/pdmodel/interactive/form/AlignmentTests.pdf
for a sample of such a file.
b) you could try to contribute some code to {{PlainTextFormatter.java}} and
{{AppearanceGeneratorHelper.java}} in
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form. Please be
aware that there is a lot of legacy code. I was planning to do a rewrite for
PDFBox 3.x
For myself it will be at least a month until I'm able to solve that.
If you prefill the form and the user opened the form with Adobe Reader later on
you could also set {{PDAcroForm.setNeedAppearances(true)}} as this will enforce
Adobe Reader to generate the appearance (how the field looks like) when opening
the form.
> Support auto size font for multiline PDTextField
> -------------------------------------------------
>
> Key: PDFBOX-3812
> URL: https://issues.apache.org/jira/browse/PDFBOX-3812
> Project: PDFBox
> Issue Type: Improvement
> Components: AcroForm
> Affects Versions: 2.0.6
> Environment: Windows 7 and Mac OSX, Java 1.8.0_121
> Reporter: Marek Zajac
> Attachments: TestPDF_gen_flatten.pdf, TestPDF_gen.pdf, TestPDF.pdf
>
>
> Hello, I ve got a simple pdf file "TestPDF.pdf" with just one text field
> named "Text1". It is set up as auto size and multiline field.
> My code :
> {code:title=GeneratePDF.java|borderStyle=solid}
> File fileTemplate = new File("/Users/xxx/Downloads/TestPDF.pdf");
> PDDocument doc = null;
> try {
> doc = PDDocument.load(fileTemplate);
> } catch (IOException e) {
> e.printStackTrace();
> }
> PDDocumentCatalog catalog = doc.getDocumentCatalog();
> PDAcroForm form = catalog.getAcroForm();
> PDTextField field = (PDTextField)form.getField("Text1");
> // field.setDefaultAppearance("/Helv 0 Tf 1 0 0 rg")
> String longText = "THIS IS A VERY VERY LONG TEXT IN A
> MULTINLINE TEXT FIELD "
> + "THIS CAN BE REALY LONG TEXT FIELD CONTAINING
> A FULL ADDRESS OF THE CUSTOMER"
> + "WE WANT TO HAVE AN AUTO SIZED FIELD WITH
> DYNAMICALY CHANGED FONT SIZE. TO TEST IT OUT WE" + "NEED AT THE END 123";
> try {
> field.setValue(longText);
> // form.flatten();
> doc.save("/Users/xxx/TestPDF_generated.pdf");
> doc.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
> {code}
>
> Please open the attached "TestPDF_gen.pdf" file in the Adobe Acrobat. It
> shows the text cut off at the end. However if you click inside the field it
> sudenly renders text properly.
> Other remarks :
> 1. If you open the "TestPDF_gen.pdf" file in the Preview (Mac OSX default pdf
> viewer) then the Text1 shows text properly auto sized.
> 2. If you do flat the form by uncommenting form.flatten(). Then the Text1 is
> cut off at the end of the text and font size is not auto. I ve tried both
> Adobe Acrobat and Preview. See the "TestPDF_gen_flatten.pdf"
> 3. I ve also tried calling setDefaultAppearance method before setting the
> field's value - field.setDefaultAppearance("/Helv 0 Tf 1 0 0 rg") but it did
> not help.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]