[
https://issues.apache.org/jira/browse/PDFBOX-3812?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17139389#comment-17139389
]
Sebastian Fieber edited comment on PDFBOX-3812 at 6/18/20, 12:27 PM:
---------------------------------------------------------------------
As suggested by Tilman Hausherr here the mail I wrote to the dev mailing list.
_"Hey,_
_we are using PDFBox for one of our products and have a proposed_
_improvement for PDFBOX-3812._
_The problem we are facing with the current implementation of_
_auto-sized multiline text fields is the following:_
_1. If the rectangle of the multiline text field has a reasonable height_
_for a few lines and only a few characters are put in the text field_
_the font will get too big, resulting in strange looking input. If_
_edited aftewards with Adobe Acrobat the font size is adjusted to 12pt_
_(like the DEFAULT_FONT_SIZE)._
_2. Words are not broken if they are too long to fit in the width of the_
_textbox. The result is that the part not fitting is cut off._
_The attached patch tries to fix these issues in the following way:_
_1. Use DEFAULT_FONT_SIZE instead of MAX_FONT_SIZE to calculate the_
_maximum line height for multiline text fields_
_2. Test if a word is longer than the width if it is the only word_
_present on a line. If yes a similar alorithm to calculate the font_
_size in 1. is used._
_If there are any problems with the patch, please let me know."_
The patch was created off 2.0.19 tag:
I just noticed that the original patch attached on the mail was the wrong one
(not cleaned up and had stuff in it it shouldn't), so sorry for this and forget
about it. This one is the right patch.
was (Author: sfieber):
As suggested by Tilman Hausherr here the mail I wrote to the dev mailing list.
_"Hey,_
_we are using PDFBox for one of our products and have a proposed_
_improvement for PDFBOX-3812._
_The problem we are facing with the current implementation of_
_auto-sized multiline text fields is the following:_
_1. If the rectangle of the multiline text field has a reasonable height_
_for a few lines and only a few characters are put in the text field_
_the font will get too big, resulting in strange looking input. If_
_edited aftewards with Adobe Acrobat the font size is adjusted to 12pt_
_(like the DEFAULT_FONT_SIZE)._
_2. Words are not broken if they are too long to fit in the width of the_
_textbox. The result is that the part not fitting is cut off._
_The attached patch tries to fix these issues in the following way:_
_1. Use DEFAULT_FONT_SIZE instead of MAX_FONT_SIZE to calculate the_
_maximum line height for multiline text fields_
_2. Test if a word is longer than the width if it is the only word_
_present on a line. If yes a similar alorithm to calculate the font_
_size in 1. is used._
_If there are any problems with the patch, please let me know."_
The patch was created off 2.0.19 tag:
[^PDFBOX-3812-break-too-long-words-and-use-default-font-size-as-max-in-multiline-fields.patch]
I just noticed that the original patch attached on the mail was the wrong one
(not cleaned up and had stuff in it it shouldn't), so sorry for this and forget
about it. This one is the right patch.
> 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
> Priority: Major
> Attachments: Autosizing.pdf,
> PDFBOX-3812-break-too-long-words-and-use-default-font-size-as-max-in-multiline-fields.patch,
> PDFBOX3812-acrobat-multiline-auto.pdf,
> PDFBOX3812-acrobat-multiline-auto.png, TestPDF.pdf, TestPDF_gen.pdf,
> TestPDF_gen_flatten.pdf, Test_TextField_Multiline_Autosize.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
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]