pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Nibali <rnib...@gmail.com>
Subject PDTextField COSName.DA token settings ignored
Date Fri, 10 Jul 2015 19:17:42 GMT

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:

} else if (field instanceof PDTextField) {
    PDTextField textField = (PDTextField) field;
    PDTextField newTextField = (PDTextField) newField;
    String value = textField.getValue();

    PDFStreamParser parser = new PDFStreamParser(new
    final List<Object> tokens = parser.getTokens();
    int setFontOperatorIndex = tokens.indexOf(Operator.getOperator("Tf"));
    Integer fontSize = ((COSNumber) tokens.get(setFontOperatorIndex -
    /* 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);


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:


 [image: Inline image 1]


[image: Inline image 2]

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:

[image: Inline image 3]

Best regards

  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message