Actually got it to work. Here's the code to do so
field_resources = PDResources.new
field_resources.put(COSName.get_pdf_name('ZaDb'),
PDType1Font::ZAPF_DINGBATS)
on_appearance_stream.cos_object.set_item(COSName::RESOURCES,
field_resources)
...
I've also added an explicit off appearance.
Thanks for the help
On Mon, Nov 21, 2016 at 11:53 AM Mikhail Slyusarev <
[email protected]> wrote:
I guess I just don't understand how to add the font resource at the right
level...
On Mon, Nov 21, 2016 at 11:34 AM Tilman Hausherr <[email protected]>
wrote:
Am 21.11.2016 um 20:19 schrieb Mikhail Slyusarev:
> Here's the PDF. I'm not sure where PDPageContentStream comes in to
> play though.
Like this:
PDPageContentStream cs = new PDPageContentStream(renderer.document,
appearanceStream);
but try the hard way first, as you almost got it to work.
re your file, I looked at
Root/AcroForm/Fields/[8]/AP/N/Yes
That one misses the resource directory with the font entry for ZaDB -
although maybe it works because ZaDb is in the default resources.
Another thing missing is the "Off" entry.
Tilman
>
> On Mon, Nov 21, 2016 at 11:02 AM Tilman Hausherr
> <[email protected] <mailto:[email protected]>> wrote:
>
> Am 21.11.2016 um 19:31 schrieb Mikhail Slyusarev:
> > I've compared it to the file you mentioned. It seems like that
> is what's
> > happening. It's not entirely clear to me where to embed the resource
> > though. I think the way I'm making the appearance stream is kind
> of a
> > mistake.
>
> I can't comment without having seen the PDF.
>
> I forgot to mention, the font must also be in the resources of the
> appearance stream, of course, as seen in
>
> Root/Pages/Kids/[5]/Annots/[14]/AP/N/Yes/Resources/Font/ZaDb
>
> > Is there a way to construct the appearance without having it all
> > be PDF syntax strings?
>
> There's a PDPageContentStream constructor that takes appearance
> streams
> as parameter so that it becomes a bit easier. Not sure if this
> works for
> checkboxes.
>
> Tilman
>
> >
> > On Mon, Nov 21, 2016 at 9:35 AM Tilman Hausherr
> <[email protected] <mailto:[email protected]>>
> > wrote:
> >
> >> Could you upload your result file somewhere? I could compare it
> with a
> >> file that has a checkbox.
> >>
> >> What may be missing is the font definition in
> Root/AcroForm/DR/Font/ZaDb
> >>
> >> To see what I mean, open this file in PDFDebugger
> >> http://www.ghostscript.com/doc/examples/annots.pdf
> >>
> >> Tilman
> >>
> >> Am 21.11.2016 um 15:32 schrieb Mikhail Slyusarev:
> >>> How is this done? I'm able to create the field... that part's
> pretty
> >>> straight forward. However, the field doesn't have an
> appearance, and
> >>> constructAppearance isn't implemented for it.
> >>>
> >>> I'm doing this in jRuby, so excuse the syntax, but here's what
> I have so
> >>> far for creating an appearance.
> >>>
> >>> field = PDCheckBox.new(form)
> >>>
> >>> field.partial_name = rf.id <http://rf.id>
> >>>
> >>> form.fields.add(field)
> >>>
> >>> rect = PDRectangle.new(
> >>> rf.x * box.width,
> >>> box.height - (rf.y * box.height) - (rf.height * box.height),
> >>> rf.width * box.width,
> >>> rf.height * box.height
> >>> )
> >>>
> >>> appearance_stream = PDAppearanceStream.new(COSStream.new)
> >>>
> >>> cs = appearance_stream.content_stream
> >>>
> >>> out = cs.create_output_stream
> >>> out.write("q\n1 1 9.3879 9.4828 re\nW\nn\nBT\n/ZaDb 7.7614
> Tf\n2.4109
> >>> 3.1142 Td\n7.4742 TL\n(x) Tj\nET\nQ\n".to_java_bytes)
> >>> out.close
> >>>
> >>> ad = COSDictionary.new
> >>> ad.set_item(COSName::YES, appearance_stream)
> >>>
> >>> appearance = PDAppearanceDictionary.new(COSDictionary.new)
> >>> appearance.normal_appearance = PDAppearanceEntry.new(ad)
> >>>
> >>> widget = field.widgets.get(0)
> >>> widget.rectangle = rect
> >>> widget.page = page
> >>> widget.printed = true
> >>> widget.appearance = appearance
> >>>
> >>> page.annotations.add(widget)
> >>>
> >>>
> >>> The magic string above is pulled from analyzing an existing
> checkbox
> >>> field on a pdf. How do I get the appearance correct (with a check
> >>> symbol)?
> >>>
> >>> Thanks,
> >>> Mikhail
> >>>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> <mailto:[email protected]>
> >> For additional commands, e-mail: [email protected]
> <mailto:[email protected]>
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> <mailto:[email protected]>
> For additional commands, e-mail: [email protected]
> <mailto:[email protected]>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]