You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2017/03/27 16:17:42 UTC

[jira] [Commented] (PDFBOX-3732) IllegalArgumentException when refreshing an appearance and no font resources are defined

    [ https://issues.apache.org/jira/browse/PDFBOX-3732?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15943544#comment-15943544 ] 

Tilman Hausherr commented on PDFBOX-3732:
-----------------------------------------

test case without external file, I also removed the DA entries. The result is a PDF that works fine with Adobe Reader.

If the patch is used, then it should also include a default DA string, e.g. "/Helv 12 Tf 0 g".
{code}
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);

PDAcroForm acroForm = new PDAcroForm(document);
document.getDocumentCatalog().setAcroForm(acroForm);

PDTextField textBox = new PDTextField(acroForm);
textBox.setPartialName("SampleField");
acroForm.getFields().add(textBox);

PDAnnotationWidget widget = textBox.getWidgets().get(0);
PDRectangle rect = new PDRectangle(50, 750, 200, 20);
widget.setRectangle(rect);
widget.setPage(page);

page.getAnnotations().add(widget);

acroForm.setNeedAppearances(true);
acroForm.getField("SampleField").getCOSObject().setString(COSName.V, "content");

ByteArrayOutputStream baos = new ByteArrayOutputStream();
document.save(baos); // this is a working PDF

document = PDDocument.load(baos.toByteArray());
acroForm = document.getDocumentCatalog().getAcroForm();
//System.out.println(acroForm.getField("SampleField").getValueAsString()); // works!
acroForm.refreshAppearances(); // boom
document.close();
{code}


> IllegalArgumentException when refreshing an appearance and no font resources are defined
> ----------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-3732
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3732
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 2.0.5
>            Reporter: simon steiner
>         Attachments: out.pdf, refreshAppearances.patch
>
>
>         PDDocument doc = PDDocument.load(new File("out.pdf"));
>         doc.getDocumentCatalog().getAcroForm().setNeedAppearances(false);
>         doc.getDocumentCatalog().getAcroForm().refreshAppearances();
>         doc.save("pdfbox.pdf");
>         doc.close();
> Exception in thread "main" java.lang.IllegalArgumentException: /DR is a required entry
> 	at org.apache.pdfbox.pdmodel.interactive.form.PDDefaultAppearanceString.<init>(PDDefaultAppearanceString.java:82)



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

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