如何在pdf中控制有效性图标的大小

时间:2013-12-09 18:26:42

标签: ruby pdf

我已经尝试至少2天来控制pdf文件的有效性图标的大小,当签名时。

图标通常由pdf阅读器设置。

我尝试过不同的解决方法:

  1. 重新标记签名注释矩形 - 重新整形
  2. 中的所有内容
  3. 重新标记签名注释外观BBox - 也是 重塑了文字和图标内容。
  4. 我还尝试重塑n2和n0层,并创建了一个新层 n5,期望能够控制它的大小而没有成功
  5. 最后,我只想单独调整有效性图标的大小。

    任何建议都应该深表感谢。

    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)
    

2 个答案:

答案 0 :(得分:1)

这不是一个显示如何修复的答案,但更多的评论认为尝试根本不是一个坏主意。但是,对于评论字段来说,它太大了。

您正在尝试制作PDF以支持Adobe已经开始逐步淘汰Adobe Reader 9的Adobe Reader功能!

Individual signature status icons removed from signature fields

  

Adobe Acrobat 9 Digital Signatures, Changes and Improvements的第10页)

因此,即使您现在使用当前的Adobe Reader实现了目标,也很容易发生在即将推出的新Adobe Reader版本中,此功能的支持将完全停止。

此外,您不会在当前的PDF规范ISO 32000-1中找到任何提及此功能(更改签名外观),更不用说即将推出的ISO 32000-2。

在Acrobat 6.0中,已经停止维护除 n0 n2 以外的图层支持:

Standard AP dictionary and layers

  

Adobe® Acrobat® SDK Digital Signature Appearances, Edition 1.0, October 2006的第8页)

答案 1 :(得分:0)

经过一些迭代后,我设法为streamN和n2以及padding_y获得了3的比例因子。我还添加了增加text_size。

有了这个,我设法减少了图标的大小,并且仍然有清晰的文字。

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 ]