Hi,
> Am 10.07.2015 um 21:17 schrieb Roberto Nibali <[email protected]>:
>
> Hello
>
> I'm still working on trying to clone form fields from one PDF to a new
> template PDF and have progressed quite well, thanks to the tremendous help of
> Maruan and Tilman. Besides some Checkbox issues, which I will report later, I
> am currently fighting with PDTextBox font size and text positioning. I'm
> using the current SVN drop as of now.
>
> Specifically, when the DA settings indicate a font size of 0 (auto, I
> presume), the resulting PDF contains the wrong font size. I have solved this
> as follows:
you are correct. Font size 0 means autosizing. That is already supported in
PDFBox (1.8.9 and 2.0.0). So there shouldn't be a need to implement it. The
issue with text formatting in general is that the details are not part of the
PDF specification. So If a form has been filled out using e.g. Adobe Acrobat it
might be that there is a difference with the look achieved by PDFBox (although
we try to be close). Sometimes even different version of Adobe Reader/Acrobat
produce slightly different results.
> } else if (field instanceof PDTextField) {
> PDTextField textField = (PDTextField) field;
> PDTextField newTextField = (PDTextField) newField;
> String value = textField.getValue();
>
> PDFStreamParser parser = new PDFStreamParser(new
> RandomAccessBuffer(newTextField.getDefaultAppearance().getBytes()));
> parser.parse();
> final List<Object> tokens = parser.getTokens();
> int setFontOperatorIndex = tokens.indexOf(Operator.getOperator("Tf"));
> Integer fontSize = ((COSNumber) tokens.get(setFontOperatorIndex -
> 1)).intValue();
> /* This specifies that the text appearing on the button by default should
> be Courier
> 8pts in size or the original size, and the color of the text is black
> (0 g = 0 setgray)
> */
> String DAtokens = "15 TL /Cour " + (fontSize == 0 ? 8 : fontSize) + " Tf
> 0 g";
> newTextField.getCOSObject().setString(COSName.DA, DAtokens);
>
> newTextField.setValue(textField.getValue());
> }
> My questions:
>
> * Is there a more sane way of achieving this, and is my approach correct?
> * Would there be a certain interest to abstract this into the API, let's say
> along the lines of: ((PDTextField) field).getDAFontSize() and ((PDTextField)
> field).setDAFontSize()
> * Why is the "15 TL" part in the DA token is disregarded by PDFBox? The issue
> I'm trying to solve is that the glyph placement inside the PDTextField is
> rather off in most cases. Example:
At that point in time only the font settings of the DA are taken into account.
This is a known limitation.
>
> Original:
>
>
>
> PDFBox:
>
>
>
> Not knowing any better way to fix this, I thought that using the TL operator
> I could fiddle around using the text lead settings. Or would there be a
> recognized operator which allows me to vertically balance the glyphs
> respecting the PDTextField appearance height?
>
> * Are there incentives to implement the various text state parameters and
> operators, as given by the PDF reference manual section 5.2, table 5.1? Or
> even better, would be the text matrix using the Tm operator:
>
>
The inline images didn't make it through due to restrictions of the mailing
list. You could send me the images privately so I can have a look.
BR
Maruan
>
>
> Best regards
>