pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: Unable to Set a String containing New Line Character into PDFBox PDTextField Object
Date Thu, 11 Aug 2016 15:56:46 GMT

> Am 11.08.2016 um 17:53 schrieb John Hewson <john@jahewson.com>:
> 
> 
>> On 11 Aug 2016, at 05:56, Yoav Tsoref <yoav.ts@intango.com> wrote:
>> 
>> Hi,
>> 
>> I am using PDFBox version 2.0.1 to dynamically update the fields of an
>> existing PDF document. When I'm trying to fill one of the fields with a
>> String that contains New Line character the following exception is thrown:
>> 
>> java.lang.IllegalArgumentException: U+000D ('controlCR') is not available
>> in this font's encoding: StandardEncoding with differences
>> at org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:345)
>> at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:286)
>> at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:315)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.PlainText$Paragraph.getLines(PlainText.java:169)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.PlainTextFormatter.format(PlainTextFormatter.java:182)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:373)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:237)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:144)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:263)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:225)
>> at
>> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:218)
>> at
>> com.myadwise.db.dao.FinancialTransactionMgr.createInvoice(FinancialTransactionMgr.java:525)
> 
> Unfortunately this is what I'd expect. PDF doesn't have the concept of a newline character,
and the current font doesn't contain one either.
> 
> We're currently in the planning by stage of introducing a new high-level text layout
API, but it's some way off.
> 
> In the meantime, it seems like setText could be made to handle newlines with only minor
changes - Maruan will likely have more to say here.

that's already taken care of in the current implementation. Maybe a bug in 2.0.1 - 2.0.2 and
2.0.3-SNAPSHOT work fine. Need to verify that.

BR
Maruan


> 
> -- John
> 
>> The API call that I'm using to insert the string into the field is:
>> 
>> PDDocument pdfDocument = PDDocument.load(<PATH_TO_TEMPLATE_PDF_FILE); //PDF
>> file was created as a template using Adobe DC
>> 
>> PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
>> 
>> acroForm.getField("invoice.to.address").setValue(billingAddress)
>> 
>> 
>> The last line is the one that throws the exception if the billingAddress
>> String contains a '/n' or a New Line (or Carriage Return) character.
>> I have searched for similar issues but couldn't find many references.
>> 
>> Any help would be appreciated!
>> Thanks,
>> Yoav
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message