You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Erik Scholtz (JIRA)" <ji...@apache.org> on 2010/01/27 18:26:35 UTC

[jira] Updated: (PDFBOX-607) Problem setting custom appearance on PDAnnotationRubberStamp

     [ https://issues.apache.org/jira/browse/PDFBOX-607?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Erik Scholtz updated PDFBOX-607:
--------------------------------

    Attachment: example2.pdf
                output_final.pdf

output_final.pdf is the PDF generated by pdfbox
example2.pdf is the PDF generated with Acrobat Pro

> Problem setting custom appearance on PDAnnotationRubberStamp
> ------------------------------------------------------------
>
>                 Key: PDFBOX-607
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-607
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 0.8.0-incubator, 1.0.0
>         Environment: Mac OS X 10.5.8 / J2SE-1.5
>            Reporter: Erik Scholtz
>            Priority: Minor
>         Attachments: example2.pdf, output_final.pdf
>
>
> I'm trying to generate a RubberStamp with a custom appearance in a PDF. I wrote the following test-code: it saves the document and I can find the image inside the pdf, by examinating the structures. But the Rubberstamp isn't shown within the PDF when opened with the Reader.
> I made a second PDF using Acrobat Pro with the same stamp - there I can see the stamp when opening with a Reader.
> Here is the test-code I wrote:
> (I came to this solution by analyzing the structure of a manually set custom RubberStamp from the Acrobat Pro document):
> //Generating a new document and adding a new page
> PDDocument document = new PDDocument();
> PDPage page = new PDPage();
> document.addPage(page);
> //Get all annotations
> List annotations = page.getAnnotations();
> //Generate a new RubberStamp
> PDAnnotationRubberStamp aRubber = new PDAnnotationRubberStamp();
> aRubber.setName("fancy_name");
> aRubber.setContents("This is the content of the generated stamp!");
> //Generate a custom appearance for the RubberStamp
> FileInputStream fin = new FileInputStream("fancyImage.jpg");
> PDJpeg mypic = new PDJpeg(document,fin);
> PDResources myResources = new PDResources();
> myResources.getXObjects().put("Im0", mypic);
> COSStream s = new COSStream(document.getDocument().getScratchFile());
> s.createUnfilteredStream();
> PDAppearanceStream myDic = new PDAppearanceStream(s);       
> myDic.setResources(myResources);
> PDAppearanceDictionary appearance = new PDAppearanceDictionary(new COSDictionary());
> appearance.setNormalAppearance(new HashMap<String, COSObjectable>());
> appearance.getNormalAppearance().put("default", myDic);
> //Set the appearance of the RubberStamp to the custom look
> aRubber.setAppearance(appearance);
> //Define and set the target rectangle
> PDRectangle myrect = new PDRectangle();
> myrect.setUpperRightX(250);
> myrect.setUpperRightY(550);
> myrect.setLowerLeftX(275);
> myrect.setLowerLeftY(575);
> aRubber.setRectangle(myrect);
> //Add the new RubberStamp to the document
> annotations.add(aRubber);
> // Finally write the new file and close it
> document.save("output_final.pdf");
> document.close();  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.