podofo / podofo

A C++17 PDF manipulation library

Home Page:https://podofo.github.io/podofo/documentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

help with signing documents

omerbrandis opened this issue · comments

these are my first steps with Podofo,
I am unable to sign a document. not sure if its due to bugs or my inability to use the lib. :-)

I was able to create a pdf using the hello world example. ( see pdf1 )
( ubuntu 16, gcc 9.4 , release build....)

Managed to build a copy of podofosign.cpp.
when I run it I encounter the following problems :

  1. if the document does not have an existing signature field ( existingSigField = false)
    then the program fails with
    terminate called after throwing an instance of 'PoDoFo::PdfError'
    what(): PdfErrorCode::InvalidHandle, An invalid handle was passed or returned, but initialized data was expected.
    Callstack:t#0 Error Source: main/PdfSignature.cpp(71)

which i've traced to
void PdfSignature::SetSignatureReason(nullable<const PdfString&> text)
{
if (m_ValueObj == nullptr)
PODOFO_RAISE_ERROR(PdfErrorCode::InvalidHandle);

so i've added "signature->EnsureValueObject();" after "signature = &page.CreateField(name, annot_rect);".
which leads me to
PoDoFo::SignDocument failing with
terminate called after throwing an instance of 'PoDoFo::PdfError'
what(): PdfErrorCode::NoNumber, A number was expected but not found.
Callstack:t#0 Error Source: main/PdfParserObject.cpp(276), Information: Object and generation number cannot be read
t#1 Error Source: main/PdfTokenizer.cpp(200), Information: Could not read number
which I am not able to figure out.
( please use pdf2 to reproduce)

btw :

  1. the supplied build files do not check for required libs version.
  2. gcc 8.4 is not supported ( not matching documentation)
  3. if podofosign.cpp gets the -out parameter, it expects the output file to already exist. ( does not make sense to me )
  4. I was not able to understand the purpose of the second parameter to SignDocument. ( i would expect all modifications to be made in memory, then externalized using "Save"
  5. when I tried podofosign on a document i created using the hello world code, it failed with document.GetPages().GetCount() = 0,
    even though the pdf seems valid, acrobat reader opens it and shows it has 2 pages. ( attached pdf1 )
    pdf1.pdf
    pdf2.pdf

:-)

Hello. I'm sorry but for signing document the best support I can provide today not looking at podofosign, which is a legacy and unsupported tool, but by pointing you to the new high level signing API with PdfSignerCms, which is very easy to use and powerful. I updated the FAQ, mentioning it, and you can find a lot of examples in the tests.

The new API is available in PoDoFo master HEAD, which is robust as much as the official releases (if not more robust). If you are stick with the 0.10.x releases, then what you were doing is correct and possibly you should look at the old FAQ which has a big focus on signing using the old low level API. So: ensure you create a new PdfSignature, ensuring it has a value object as you were doing (this is not necessary anymore in PoDoFo master HEAD), and ensure you will sign a stream that has the previous PDF content, that is: the same file from which you loaded the document, or a dynamic memory buffer where you previously copied the PDF content (all of these examples are in the old FAQ).

If you have further problems please open a new issue and show some short/standalone code. Don't refer to podofosign, as I don't look at that code.

gcc 8.4 is not supported ( not matching documentation)

Yes, this is a known issue. It broke recently (patch welcome to fix it). I updated the README.

the supplied build files do not check for required libs version.

Yes, correct. Patch welcome to enhance the current situation, wherever possible.