1

我正在使用 podofo 0.9.3 库使用 PdfSigIncMemDocument 类对 pdf 文档进行数字签名。我能够毫无问题地对 pdf 进行数字签名,但输出的 pdf 文件大小非常大。

这是我的代码

    PdfSigIncMemDocument    doc("e:\\sample.pdf");
    char                    *buffer = NULL;
    buffer = (char *)malloc(809600);
    PdfOutputDevice         output(buffer, 809600);
    PdfSignOutputDevice     signOutput(&output);
    signOutput.SetSignatureSize(2048);
    printf( "Page count:%d\n", doc.GetPageCount());

    PdfSigIncSignatureField *sign = doc.GetSignatureField();
    sign->SetSignatureDate(PdfDate());
    sign->SetSignatureReason(L"I dont agree");
    sign->SetSignatureImage("e:\\sign.jpg", 0, 100, 200, 100, 100);
    sign->SetSignatureText(L"Hello World", 0, 100, 200, 100, 100, 12);
    doc.Initialize();
    doc.CreateVisualSign();
    doc.Write(&signOutput);
    printf( "Has Signature:%d\n", signOutput.HasSignaturePosition());
    char buff[809600] = {0};
    size_t len;
    BYTE *Signature = NULL;
    DWORD cbSignature = 0;

    signOutput.AdjustByteRange();
    signOutput.Seek(0);
    len = signOutput.ReadForSignature(buff, 809600);
    printf("total tbs size: %d\n", len);
    SignMessage( (BYTE *)buff, len, &Signature, &cbSignature);//Digital signing using MSCAPI
    printf("signature size: %d\n", cbSignature);
    const PoDoFo::PdfData *sig = new PoDoFo::PdfData((char *)Signature, cbSignature);
    signOutput.SetSignature(*sig);
    signOutput.Flush();

    FILE *fp = NULL;
    fp = fopen( "e:\sign.pdf", "wb" );
    fwrite( buffer, signOutput.GetLength(), 1, fp );
    fclose(fp);

sample.pdf 大小为 31KB,而输出 sign.pdf 大小为 506KB。

有人可以帮助解决这个问题吗?

4

0 回答 0