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<PdfSignature>(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](https://github.com/podofo/podofo/files/14558910/pdf1.pdf)
[pdf2.pdf](https://github.com/podofo/podofo/files/14558912/pdf2.pdf)



:-)






help with signing documents
This is a GitHub Issue
repo:podofo
owner:podofo
Title : help with signing documents
Issue date:

--- start body ---
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<PdfSignature>(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](https://github.com/podofo/podofo/files/14558910/pdf1.pdf)
[pdf2.pdf](https://github.com/podofo/podofo/files/14558912/pdf2.pdf)



:-)






--- end body ---
