如何使用 secureblackbox 进行数字签名 pdf 时添加任何图像

问题描述 投票:0回答:1

我想使用 SecureBlackBox 对 PDF 文档进行数字签名。 我想添加可见的签名并添加一些 jpg 作为背景数据。

如何将此 JPG 图像添加到 FSigner.Signature.Background... 属性? 什么是 CustomBackgroundContentStream 以及如何使用它! 我想控制图像的位置和大小。 SecureBlackBox 在签名者示例中不包含图像,我无法弄清楚。

delphi digital-signature
1个回答
0
投票

此 PDF 中有一些关于如何执行此操作的好示例:

https://www.nsoftware.com/kb/articles/file/widgets.pdf

在 2022 版本中使用 JPEG 是这样的,C 代码:

Signer.Widget.BackgroundStyle = pwbsCustom;
Signer.Widget.BackgroundImageType = pwitJPEG;
Signer.Widget.BackgroundData = ReadAllBytes(“Background120x120.jpg”);
Signer.Widget.BackgroundImageWidth = 120;
Signer.Widget.BackgroundImageHeight = 120;

但答案取决于您使用的版本(Signer.Widget.BackgroundData 可能是旧版本中的 Signer.Signature.BackGround.Data 或 pascal 而不是 C 等)。

PDF 中的一个示例使用了 CustomBackgroundContentStream。基本上,您可以使用 PDF“样式”中的矢量图形定义背景。在 C 中,它看起来像这样(将 /n 和 /r 更改为 pascal 中相应的 #13 和 #10):

Signer.Widget.BackgroundStyle = pwbsCustom;
Signer.Widget.CustomBackgroundContentStream = “0.9 0.5 0.5 rg\r\n” + “0 i\r\n” +
“0 0 “ + IntToStr(Signer.NewSignature.Width) + “ “ + IntToStr(Signer.NewSignature.Height) +
“ re\r\n” + “f\r\n” + “0.83 0.9 0.9 rg\r\n” +
“2 2 “ + IntToStr(Signer.NewSignature.Width - 4) + “ “ + IntToStr(Signer.NewSignature.Height - 4) +
“ re\r\n” + “f\r\n”;

在这里将rgb设置为一种颜色(0.9 0.5 0.5 rg),然后初始化(0 i)添加一个矩形(re),然后“f”填充它。他们添加 2 个矩形以获得 3D 外观。

© www.soinside.com 2019 - 2024. All rights reserved.