相关疑难解决方法(0)

附件损害签字第2部分

我创建了一个代码,用于将图像添加到现有的pdf文档中,然后使用PDFBox对其进行签名(请参阅下面的代码).

代码很好地添加了图像和签名.但是,在某些文档中,Acrobat Reader会抱怨"签名字节范围无效".

这个问题似乎是一样的中提到的问题这个问题.该问题的答案更详细地描述了问题:问题是我的代码在文档(流和表)中留下了交叉引用类型的混合.实际上,由于这些问题造成的问题,有些文件甚至无法打开.

我的问题是:我该如何防止这种情况发生?如何在不创建多个交叉引用类型的情况下将图像添加到现有pdf文档?

public class TC3 implements SignatureInterface{

private char[] pin = "123456".toCharArray();
private BouncyCastleProvider provider = new BouncyCastleProvider();
private PrivateKey privKey;
private Certificate[] cert;

public TC3() throws Exception{
    Security.addProvider(provider);
    KeyStore keystore = KeyStore.getInstance("PKCS12", provider);        
    keystore.load(new FileInputStream(new File("resources/IIS_keystore.pfx")), pin.clone());
    String alias = keystore.aliases().nextElement();
    privKey = (PrivateKey) keystore.getKey(alias, pin);
    cert = keystore.getCertificateChain(alias);
}

public void doSign() throws Exception{
    byte inputBytes[] = IOUtils.toByteArray(new FileInputStream("resources/rooster.pdf"));
    PDDocument pdDocument = PDDocument.load(new ByteArrayInputStream(inputBytes));
    PDJpeg ximage = new PDJpeg(pdDocument, ImageIO.read(new File("resources/logo.jpg")));
    PDPage page …
Run Code Online (Sandbox Code Playgroud)

pdfbox

5
推荐指数
1
解决办法
911
查看次数

标签 统计

pdfbox ×1