Do you mean adding something like this?
ap.getStream().setItem(COSName.FRM, objectForm);


On Tue, Oct 11, 2016 at 11:34 AM, Maruan Sahyoun <sahy...@fileaffairs.de>
wrote:

> Hi,
>
> > Am 11.10.2016 um 11:29 schrieb Gilad Denneboom <
> gilad.denneb...@gmail.com>:
> >
> > Here's what I have so far (I skipped the scaling part, just to see if I
> can
> > get any kind of results...):
> >
> >                    // - load your image as a PDXObjectImage
> >                    BufferedImage bImg = ImageIO.read(new
> > File(imageFilePath));
> >                    PDXObjectImage image = new PDJpeg(doc, bImg);
> >                    COSStream s = image.getCOSStream();
> >
> >                    // - create a PDXObjectForm with the image as a
> > resource entry
> >                    PDXObjectForm objectForm = new PDXObjectForm(s);
> >                    PDResources resources = new PDResources();
> >                    resources.addXObject(objectForm, "Im0");
> >                    objectForm.setResources(resources);
> >
> >                    // - put that into the /I key of the fields MK entry
> >
> > f.getWidget().getAppearanceCharacteristics().getDictionary().setItem(
> COSName.I,
> > objectForm);
> >
> >                    // - add the PDXObjectForm you created above to the
> > Resources Entry of the appearance stream
> >                    PDAppearanceStream ap = (PDAppearanceStream)
> > f.getWidget().getAppearance().getNormalAppearance().get("default");
> >                    Map<String, PDXObject> xobjectsMap =
> > ap.getResources().getXObjects();
> >                    xobjectsMap.put("FRM", objectForm);
> >
> > f.getWidget().getAppearance().getNormalAppearance().put("default", ap);
> >
> > Do you see what I'm doing wrong, because the button is still blank when I
> > open the edited file? …
>
> from the code you are not setting the appearance stream content. So the
> definitions are in place but they are not used.
>
> BR
> Maruan
>
>
>
> > I got the keys ("Im0", "FRM") from inspecting a sample file I created in
> > Acrobat.
> >
> > On Tue, Oct 11, 2016 at 10:26 AM, Maruan Sahyoun <sahy...@fileaffairs.de
> >
> > wrote:
> >
> >> Hi,
> >>
> >>> Am 11.10.2016 um 10:07 schrieb Gilad Denneboom <
> >> gilad.denneb...@gmail.com>:
> >>>
> >>> Thank for the info, Maruan. I implemented some of what you've described
> >>> already, and will try to do the rest next...
> >>> Maybe this is a a good "feature" request for future versions?
> >>
> >> yes it is - and I'm planning to add that if I find the time but I'm
> >> currently very limited.
> >>
> >> If you'd like to share some of your code please do so - would be good to
> >> have a new ticket for that by then.
> >>
> >> Maruan
> >>
> >>
> >>
> >>>
> >>> On Tue, Oct 11, 2016 at 8:30 AM, Maruan Sahyoun <
> sahy...@fileaffairs.de>
> >>> wrote:
> >>>
> >>>> Hi Gilad,
> >>>>
> >>>>> Am 10.10.2016 um 23:28 schrieb Gilad Denneboom <
> >>>> gilad.denneb...@gmail.com>:
> >>>>>
> >>>>> I posted this question to SO
> >>>>> <http://stackoverflow.com/questions/39958843/how-to-
> >>>> import-an-icon-to-a-button-field-in-a-pdf-using-pdfbox>,
> >>>>> but thought I might get better traction here...
> >>>>>
> >>>>> I'm looking for a way to set the normal appearance of a button field
> >> in a
> >>>>> PDF file to an image file, but am not finding any information about
> >> this
> >>>>> process. The closest I could find was the opposite, ie how to extract
> >> an
> >>>>> icon from a button field to a stand-alone image file, here: How can i
> >>>>> extract image from button icon in PDF using Apache PDFBox?
> >>>>> <http://stackoverflow.com/questions/33295483/how-can-i-
> >>>> extract-image-from-button-icon-in-pdf-using-apache-pdfbox>
> >>>>
> >>>> currently PDFBox doesn't have a high level API to set that. The
> easiest
> >> is
> >>>> to create a sample with Acrobat and recreate that.
> >>>>
> >>>> The basics steps are
> >>>>
> >>>> - load your image as a PDXObjectImage
> >>>> - create a PDXObjectForm with the image as a resource entry
> >>>> - put that into the /I key of the fields MK entry
> >>>>
> >>>> Now this gives you the "Design" part so Readers can use that to
> >> regenerate
> >>>> the appearance stream. At that point in time the Icon is not yet
> >> visible as
> >>>> it's not part of the appearance stream
> >>>>
> >>>> For the appearance stream
> >>>>
> >>>> - add the PDXObjectForm you created above to the Resouces Entry of the
> >>>> appearance stream
> >>>> - call the PDXObjectForm in the appearance stream with a
> transformation
> >>>> matrix before to scale the PDXObjectForm to fit the buttons dimension.
> >>>>
> >>>> BR
> >>>> Maruan
> >>>>
> >>>>
> >>>>
> >>>>>
> >>>>> Thanks in advance!
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> >>>> For additional commands, e-mail: users-h...@pdfbox.apache.org
> >>>>
> >>>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> >> For additional commands, e-mail: users-h...@pdfbox.apache.org
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> For additional commands, e-mail: users-h...@pdfbox.apache.org
>
>

Reply via email to