如何向 PDF 添加可打印或不可打印的位图图章?

How to add a printable or non-printable bitmap stamp to a PDF?

我想向 PDF 文件添加位图图章,根据 Acrobat Reader 的实际打印设置,该图章可打印或不可打印。

即when user selects in AR Print dialog combo box the option "Document" - then it would not be printed, but when "Document and stamps" is selected then the bitmap would print.

现在我可以创建可打印或不可打印的位图,但我无法创建可打印和不可打印的位图,具体取决于用户的选择

使用PdfStamper

这可能吗?

my book, more specifically in the TimeTableAnnotations3 示例的第 7 章中描述了创建图章注释:

PdfAnnotation annotation = PdfAnnotation.createStamp(stamper.getWriter(),
    rect, "Press only", "NotForPublicRelease");
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);

如果您查看打印预览,您会发现如果打印没有图章的文档,这些注释不会显示:

在 C# 中,代码与 Java 代码非常相似:

 PdfAnnotation annotation = PdfAnnotation.CreateStamp(
     stamper.Writer, rect, "Press only", "NotForPublicRelease"
 );
 annotation.Flags = PdfAnnotation.FLAGS_PRINT;

请注意,PDF 查看器至少应具有以下名称的预定义图标:

  • 已批准,
  • 实验性的,
  • 未获批准,
  • 原样,
  • 已过期,
  • NotForPublicRelease,
  • 机密,
  • 决赛,
  • 已售出,
  • 部门,
  • 评论,
  • 绝密,
  • 草稿,
  • 公开发布。

这些图标的外观因观众而异。

我将在此处添加可行的解决方案,因为从提供的示例中找出它并不是很简单。现在 PDF 文档中有一个自定义位图图章注释,单击时,会出现数字签名的属性 window。

PdfReader reader = new PdfReader(this.inputPDF);
PdfStamper stamper = new PdfStamper(reader, fs);
PdfSignatureAppearance sap;
Rectangle stampRect = null;
//Add stamp annotation
if (StampImagePath != null && StampImagePath.Length > 0 && File.Exists(StampImagePath))
{
    Image stampImg = Image.GetInstance(stampImagePath);
    Rectangle location = new Rectangle(stampXpos, stampYpos, stampXpos + stampImg.Width, stampYpos + stampImg.Height);
    PdfAnnotation pdfStamp = PdfAnnotation.CreateStamp(
        stamper.Writer, location, null, Guid.NewGuid().ToString());                    
    stampImg.SetAbsolutePosition(0, 0);
    PdfAppearance app = stamper.GetOverContent(1).CreateAppearance(stampImg.Width, stampImg.Height);
    app.AddImage(stampImg);
    pdfStamp.SetAppearance(PdfName.N, app);
    pdfStamp.SetPage();
    pdfStamp.Flags = PdfAnnotation.FLAGS_PRINT;
    stamper.AddAnnotation(pdfStamp, 1);
    stampRect = location;
}

....
//After signing the document set visible signature to the annotation rectangle
if (stampRect!=null)
      sap.SetVisibleSignature(stampRect, 1, "SignatureESift");