Free Support Forum - aspose.com

How can I use Signature with C++

Hi,

I’m trying to check and remove Signature from pdf files.
Can anybody tell how to do it?
Thanks

This is my test code

    auto sign = System::MakeObject<Aspose::Pdf::Facades::PdfFileSignature>();
    sign->BindPdf(u"东光县第二水厂改扩建项目二标段设备安装(工程量清单)(1) - 副本.PDF");

    if (sign->ContainsSignature()) {
        printf("有签名\n");
    }
    else {
        printf("没有签名\n");
    }

But got error:
0x00007FFE68F7A719 处(位于 pdfTest.exe 中)有未经处理的异常: Microsoft C++ 异常: System::ExceptionWrapper<System::Details_ArgumentOutOfRangeException>,位于内存位置 0x0000009424DFCD10 处。 出现了

@kngstr

Would you please share the sample PDF as well. We will test the scenario in our environment and address it accordingly.

@asad.ali

My test file is

So, is my test code right?

@kngstr

We have logged an issue as PDFCPP-1493 in our issue tracking for this case. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali

It seems to be fixed. Does 20.12 include this fix.
Thanks.

@kngstr

The issue has been fixed in 21.1 version of the API which will be released in January 2021. You will surely receive a notification as soon as the fixed-in version is published.

@asad.ali

Thanks.

1 Like

@asad.ali

Today I tested this file again.
It failed with save();
But works with save(u"导热硅胶2021REACH英文-removed.pdf");
Another problem : the file saved with 导热硅胶2021REACH英文-removed.pdf, still can not be edit. And have signature warnning.图片.png (16.8 KB)

Test SDK: Pdf for C++ 21.3
License: Loaded

Test code:

void pdfRemoveSignature() {

    auto filename = System::String(u"导热硅胶2021REACH英文.pdf");
 
    auto sign = System::MakeObject<Aspose::Pdf::Facades::PdfFileSignature>();
    sign->BindPdf(filename);
 
    if (sign->ContainsSignature()) {
        printf("有签名\n");
    }
    else {
        printf("没有签名\n");
        return;
    }
    auto names = sign->GetSignNames();
    for (int i = 0; i < names->get_Count(); i++) {
        std::cout << names->idx_get(i) << "\n";
        sign->RemoveSignature(names->idx_get(i));
    }
    sign->Save();// (u"导热硅胶2021REACH英文-removed.pdf");
}

Exception:
code+exception.zip (1.2 KB)

@kngstr

We have logged another issue as PDFCPP-1570 in our issue tracking system for further investigation. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali

Another file with System::ApplicationException: Invalid signature object.
致尚 五孔带或不带开关 质检报告.zip (2.4 MB)

@kngstr

We have logged another ticket as PDFCPP-1573 in our issue tracking system for this file. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali

How can I remove signature of one page.
I got a pdf file which got System::ApplicationException: You cannot change this document because it is certified.
I tried to split(OK), add signature(Failed), remove the first page and add signature(OK).
This file cannot be uploaded. Sorry.

@kngstr

You can please try using RemoveSignature() method of the API in order to remove the signatures.

@asad.ali

Still the same.

@kngstr

We are afraid that we cannot address the issue until we get a sample PDF that is causing problem at your end. Please try to manage a sample document to share with us so that we can further proceed to assist you accordingly.

@asad.ali

This file is not allowed to be shared. Sorry.

@kngstr

It is fine and we understand your stance. Please feel free to reach us in case you need further assistance.