pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mickael Marrache <mickaelmarra...@gmail.com>
Subject Text appears reverted in textbox
Date Wed, 26 Apr 2017 06:19:06 GMT
Hi,

I'm trying to fill a PDF form using PDFBox 2.0.5 as follows:

PDDocument pdfDocument =
PDDocument.load(this.getClass().getClassLoader().getResourceAsStream("form.pdf"));
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();

PDResources formResources = acroForm.getDefaultResources();
PDTrueTypeFont font = (PDTrueTypeFont)
formResources.getFont(COSName.getPDFName("David,Bold"));

TrueTypeFont ttFont = font.getTrueTypeFont();

PDFont font2 = PDType0Font.load(pdfDocument, ttFont, true);
ttFont.close();

formResources.put(COSName.getPDFName("F0"), font2);

if (acroForm != null) {
PDTextField field = (PDTextField) acroForm.getField("full_name");
field.setDefaultAppearance("/F0 10 Tf 0 g");
field.setValue(/* hebrew text here*/);
}

File targetFile = File.createTempFile("", ".pdf");
pdfDocument.save(targetFile);
pdfDocument.close();

The reason I embed the David,Bold font is explained here
http://stackoverflow.com/questions/42903217/write-cyrillic-chars-into-pdf-form-fields-with-pdfbox
.

The issue is that the resulting PDF file has the text in the full_name
textbox displayed in the reverse direction. However, if I click on the
textbox, the text appears correctly. I precise that the text filled in the
textbox is in Hebrew (right-to-left).

Any idea?

Thanks,
Mickael

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