On Mon, 2016-09-26 at 15:32 +0000, Thomas Szendefi wrote:
> That works fine, but only for files not containing form fields.

        Hi,
just a little follow up, also to let you know that I didn't forget of
this.

The attached is a patch, which applies on top of the svn trunk of
PoDoFo (currently at revision 1785), which partially addresses the
issue. It's partially, because it still fails for linearized PDF files.
That part requires more thinking.
        Bye,
        zyx 

-- 
http://www.litePDF.cz                                 i...@litepdf.cz
Index: src/doc/PdfSigIncMemDocument.cpp
===================================================================
--- src/doc/PdfSigIncMemDocument.cpp	(revision 1785)
+++ src/doc/PdfSigIncMemDocument.cpp	(working copy)
@@ -310,15 +310,11 @@ PdfAcroForm* PdfSigIncMemDocument::GetEx
        if(pdfRef.IsIndirect()) {
             PdfObject* pOldFields = pOldAcroForm->GetObject()->GetDictionary().GetKey( PdfName("Fields") );
             if(pOldFields) {
-               if(pOldFields->GetDataType() == ePdfDataType_Array ) {
-                  pdfRef.SetObjectNumber(pOldAcroForm->GetObject()->Reference().ObjectNumber() - 1);
-                  this->GetObjects().SetObjectCount(pdfRef);
-                  PdfObject *pNewObj = this->GetObjects().CreateObject();
-                  m_pAcroForms = new PdfAcroForm( this, pNewObj, ePdfAcroFormDefaultAppearance_None );
-                  this->GetCatalog()->GetDictionary().AddKey( "AcroForm", m_pAcroForms->GetObject()->Reference() );   
-               } else if(pOldFields->GetDataType() == ePdfDataType_Reference ) {
-                  m_pAcroForms = pOldAcroForm;
-               }
+               pdfRef.SetObjectNumber(pOldAcroForm->GetObject()->Reference().ObjectNumber() - 1);
+               this->GetObjects().SetObjectCount(pdfRef);
+               PdfObject *pNewObj = this->GetObjects().CreateObject();
+               m_pAcroForms = new PdfAcroForm( this, pNewObj, ePdfAcroFormDefaultAppearance_None );
+               this->GetCatalog()->GetDictionary().AddKey( "AcroForm", m_pAcroForms->GetObject()->Reference() );
             } else {
                pdfRef.SetObjectNumber(pOldAcroForm->GetObject()->Reference().ObjectNumber() - 1);
                this->GetObjects().SetObjectCount(pdfRef);
@@ -327,10 +323,12 @@ PdfAcroForm* PdfSigIncMemDocument::GetEx
                this->GetCatalog()->GetDictionary().AddKey( "AcroForm", m_pAcroForms->GetObject()->Reference() );
             }
        } else {
-          m_pAcroForms = pOldAcroForm;
+          PdfObject *pNewObj = this->GetObjects().CreateObject();
+          m_pAcroForms = new PdfAcroForm( this, pNewObj, ePdfAcroFormDefaultAppearance_None );
+          this->GetCatalog()->GetDictionary().AddKey( "AcroForm", m_pAcroForms->GetObject()->Reference() );
        }
     }        
-    
+
     return m_pAcroForms;
 }
 
@@ -404,13 +402,12 @@ void PdfSigIncMemDocument::CreateAnnotat
    PdfAnnotation* pAnnot = new PdfAnnotation(pPage, ePdfAnnotation_Widget, m_SignRect, &this->GetObjects());
    pdf_int64 flags = 132;
    pAnnot->GetObject()->GetDictionary().AddKey("F", PdfObject(flags));
-   PdfAcroForm *pAcroForm = this->GetAcroForm(); 
+   PdfAcroForm *pAcroForm = this->GetAcroForm();
 
    if(pAcroForm) {
-      if(!pAcroForm->GetObject()->GetDictionary().HasKey(PdfName("SigFlags"))) {
-         pdf_int64 val = 3;
-         pAcroForm->GetObject()->GetDictionary().AddKey("SigFlags", PdfObject(val));
-      }
+      pAcroForm->GetObject()->GetDictionary().RemoveKey(PdfName("SigFlags"));
+      pdf_int64 val = 3;
+      pAcroForm->GetObject()->GetDictionary().AddKey("SigFlags", PdfObject(val));
 
       PdfSignatureField signField( pAnnot, pAcroForm, this);
 
@@ -435,15 +432,20 @@ void PdfSigIncMemDocument::CreateAnnotat
          PdfPage *pPage = m_PagesRef[0];
 
          PdfObject *pAnnot = pPage->GetOwnAnnotationsArray(false, m_Document);
-         if(!pAnnot)
-            pAnnot = pPage->GetOwnAnnotationsArray(true, m_Document); 
-         else {
+         if(!pAnnot) {
+            pAnnot = pPage->GetOwnAnnotationsArray(true, this);
+         } else {
             if (pPage->GetObject()->GetDictionary().HasKey( "Annots" ) )  {
                PdfObject *pTmpObj = pPage->GetObject()->GetDictionary().GetKey( "Annots" );
                if(pTmpObj->IsReference()) {
                   PdfObject *newAnnot = new PdfObject(*pAnnot);
                   this->GetObjects().push_back(newAnnot);
                   pAnnot = newAnnot;
+               } else if (pTmpObj->IsArray()) {
+                  pAnnot = pPage->GetOwnAnnotationsArray(true, this);
+                  pAnnot->GetArray() = pTmpObj->GetArray();
+               } else {
+                  PODOFO_RAISE_ERROR(ePdfError_InternalLogic);
                }
             }
          }
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to