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
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