0

I've been trying for at least 2 days now to control the size of the validity icon of a pdf file, when signed.

The icon is set by the pdf reader usually.

I've tried different approaches to the problem :

  1. Redimensioned the Signature Annotation Rectangle - which reshaped all the contents within
  2. Redimensioned the Signature Annotation Appearance BBox - which also reshaped the text and icon contents.
  3. I've also tried to reshape n2 and n0 layers, and created a new one n5, expecting to be able to control it's size without success

In the end, I would just want to individually resize the validity icon.

Any suggestions shall be deeply appreciated.

dsblank = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
dsblank.Type=Name.new("XObject")
dsblank.Resources = Resources.new
dsblank.BBox = [ 0, 0, width, height ]
dsblank.draw_stream('% DSBlank')  


n2 = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
n2.Resources = Resources.new
n2.BBox = [ 0, 0, width, height ]
n2.draw_stream('% DSBlank')

n5 = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
n5.Resources = Resources.new
n5.BBox = [ 0, 0, width, height ]
n5.write(caption,x: padding_x, y: padding_y, size: text_size, leading: text_size )

sigannot = Annotation::Widget::Signature.new
sigannot.Rect = Rectangle[ llx: x, lly: y, urx: x+width, ury: y+height ]
sigannot.F = Annotation::Flags::PRINT #sets the print mode on

#
# Creates the stream for the signature appearance
#
streamN = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
streamN.BBox = [ 0, 0,width, height]
streamN.Resources = Resources.new
streamN.Resources.add_xobject(Name.new("n0"), dsblank)
streamN.Resources.add_xobject(Name.new("n1"), dsblank)
streamN.Resources.add_xobject(Name.new("n2"), n2)
streamN.Resources.add_xobject(Name.new("n3"), dsblank)
streamN.Resources.add_xobject(Name.new("n5"), n5)
streamN.draw_stream('q 1 0 0 1 0 0 cm /n0 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n1 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n2 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n3 Do Q')
streamN.draw_stream('q 1 0 0 1 0 0 cm /n5 Do Q')

sigannot.set_normal_appearance(streamN)

page.add_annot(sigannot)
MrWater
  • 1,797
  • 4
  • 20
  • 47

2 Answers2

1

This is not an answer showing how to fix it but more a comment arguing that it is a bad idea to try it at all. It is too big for a comment field, though.

You are trying to manufacture PDFs to support an Adobe Reader feature which Adobe has started phasing out a long time ago, with Adobe Reader 9!

Individual signature status icons removed from signature fields

(page 10 of Adobe Acrobat 9 Digital Signatures, Changes and Improvements)

Thus, even if you achieve your goal for now with the current Adobe Reader, it may very easily happen that in upcoming new Adobe Reader version support for this feature will completely be stopped.

Furthermore you wont find any mentioning of this feature (changing signature appearances) in the current PDF specification ISO 32000-1, let alone the upcoming ISO 32000-2.

Also maintenance of support for layers except n0 and n2 had already been stopped in Acrobat 6.0:

Standard AP dictionary and layers

(page 8 of Adobe® Acrobat® SDK Digital Signature Appearances, Edition 1.0, October 2006)

mkl
  • 90,588
  • 15
  • 125
  • 265
  • For more details, in particular in relation to PDF norms, see [this answer](https://stackoverflow.com/a/40391641/1729265). – mkl May 07 '19 at 12:11
0

After some iterations I managed to get a scale factor of 3 for streamN and n2, as well as padding_y. I also add to increase the text_size.

With that I managed to reduce the size of the icon, and still have legible text.

n2 = Annotation::AppearanceStream.new
n2.Resources = Resources.new
n2.BBox = [ 0, 0, width*3, height*3 ]
n2.write(caption,x: padding_x, y: padding_y*3, size: text_size, leading: text_size )

sigannot = Annotation::Widget::Signature.new
sigannot.Rect = Rectangle[ llx: x, lly: y, urx: x+width, ury: y+height ]
sigannot.F = Annotation::Flags::PRINT #sets the print mode on

#
# Creates the stream for the signature appearance
#
streamN = Annotation::AppearanceStream.new.setFilter(:FlateDecode)
streamN.BBox = [ 0, 0, width*3, height*3 ]
MrWater
  • 1,797
  • 4
  • 20
  • 47