Am 12.06.2015 um 18:59 schrieb Kevin Ternes:
Tilman wrote:
From: Tilman Hausherr [mailto:[email protected]]
Sent: Thursday, June 11, 2015 4:27 PM
To: [email protected]
Subject: Re: Setting a border color on a PDTextBox
Am 11.06.2015 um 22:44 schrieb Kevin Ternes:
I am using PDFBox 1.8.9 to change an existing PDF.
The requirement is to change an existing field so that the text is Helvetica
Bold and bordered with a given color.
A mockup of the desired PDF is here:
https://dl.dropboxusercontent.com/u/3103884/dev/PdfBoxMockupCapture.png
Given PDDocument pdDocument...:
PDDocumentCatalog catalog = pdDocument.getDocumentCatalog();
PDAcroForm pdAcroForm = catalog.getAcroForm();
PDField pdField = pdAcroForm.getField(fieldName);
COSDictionary pdFieldDictionary = pdField.getDictionary();
COSString defaultAppearance = (COSString)
pdFieldDictionary.getDictionaryObject(COSName.DA);
if (defaultAppearance != null) {
pdFieldDictionary.setString(COSName.DA, "/HeBo 9 Tf 0 g");
}
PDGamma pdGamma = new PDGamma();
pdGamma.setR(0);
pdGamma.setG(1);
pdGamma.setB(0);
PDAppearanceCharacteristicsDictionary pdApDict = new
PDAppearanceCharacteristicsDictionary(pdFieldDictionary);
pdApDict.setBorderColour(pdGamma);
PDTextbox pdTextBox = new PDTextbox(pdAcroForm, pdFieldDictionary);
PDAppearance pdAppearance = new PDAppearance(pdAcroForm, pdTextBox);
pdAppearance.setAppearanceValue(PDLayoutAttributeObject.BORDER_STYLE_S
OLID);
I am getting the Helvetica Bold change but I am missing the colored border.
Can anyone tell me what I am missing or doing wrong?
Try this:
http://qnalist.com/questions/4842300/form-elements-not-visible
PDAnnotationWidget fieldAnnot = pdTextBox.getWidget();
fieldAnnot.setAppearanceCharacteristics(pdApDict);
Tilman
That is not working for me either.
I stole all the code on the referenced qnalist page (see below) but I still do
not get the solid colored border that I am looking for.
PDDocumentCatalog catalog = pdDocument.getDocumentCatalog();
PDAcroForm pdAcroForm = catalog.getAcroForm();
PDField pdField = pdAcroForm.getField(fieldName);
COSDictionary pdFieldDictionary = pdField.getDictionary();
PDTextbox pdTextBox = new PDTextbox(pdAcroForm, pdFieldDictionary);
PDAnnotationWidget fieldAnnot = pdTextBox.getWidget();
PDAppearanceCharacteristicsDictionary fieldAppearance = new
PDAppearanceCharacteristicsDictionary(new COSDictionary());
PDGamma colourGreen = new PDGamma();
colourGreen.setR(0);
colourGreen.setG(1);
colourGreen.setB(0);
fieldAppearance.setBorderColour(colourGreen);
PDBorderStyleDictionary fieldBorderStyle = new PDBorderStyleDictionary();
fieldBorderStyle.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
fieldBorderStyle.setWidth(2f);
fieldAnnot.setAppearanceCharacteristics(fieldAppearance);
fieldAnnot.setBorderStyle(fieldBorderStyle);
If anyone can give me another hint, it would be much appreciated.
Could you please open the created PDF with an editor like NOTEPAD++ and
post the readable part? What I'm interested is the parts with /MK and
with /BC:
5 0 obj
<<
/FT /Tx
/T (SampleField)
/Type /Annot
/Subtype /Widget
/Rect [50.0 750.0 250.0 800.0]
/MK 7 0 R <===========================
/V (English form contents)
/AP 8 0 R
>>
endobj
6 0 obj
<<
/Font 9 0 R
>>
endobj
7 0 obj
<<
/BC [0.0 1.0 0.0] <===========================
>>
endobj
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]