Hi Ethan, 

I had to make several modifications to PoDoFo to fully
support digital signature as specofied in ISO 32000 and PAdES
specifications. 

In the next days I'll update the latest version of
podofo on SVN with my changes. 

If you can wait a couple of weeks you
will find the updated version. 

Regards, 

---
Ugo
Chirico
http://www.cryptware.com
blog:
http://www.ugochirico.com
linkedin:
http://www.linkedin.com/in/ugochirico
------------------------------

Il
01-04-2013 12:14 Ethan.Lee.W ha scritto: 

> hi: 
> 
> my english is so
bad.so,expression is not clear also hope forgive. 
> 
> I made several
modifications to podofo to correctly support digital signature,multiple
digital signature and add signature appearance.
> 
> it must be appended
that pdf document update. so I made several modifications.
> 
> void
PdfWriter::WritePdfObjects( PdfOutputDevice* pDevice, const
PdfVecObjects& vecObjects, PdfXRef* pXref ) 
> { 
> TCIVecObjects
itObjects = vecObjects.begin(); 
> TCIPdfReferenceList itFree =
vecObjects.GetFreeObjects().begin(); 
> 
> while( itObjects !=
vecObjects.end() ) 
> { 
> //only write new Objects and modified Objects

> PdfObject* oldObject =
this->m_pOldDocParser->GetObjects()->GetObject((*itObjects)->Reference());

> std::string strOldObject; 
> if (oldObject != NULL) 
> { 
>
oldObject->ToString(strOldObject); 
> std::string strCurrObject; 
>
(*itObjects)->ToString(strCurrObject); 
> if
(strCurrObject.compare(strOldObject) == 0) 
> { 
> ++itObjects; 
>
continue; 
> } 
> } 
> pXref->AddObject( (*itObjects)->Reference(),
pDevice->Tell(), true ); 
> // Make sure that we do not encrypt the
encryption dictionary! 
> (*itObjects)->WriteObject( pDevice,
m_eWriteMode, 
> ((*itObjects) == m_pEncryptObj ? NULL : m_pEncrypt) );

> 
> ++itObjects; 
> } 
> 
> while( itFree !=
vecObjects.GetFreeObjects().end() ) 
> { 
> pXref->AddObject( *itFree,
0, false ); 
> ++itFree; 
> } 
> } 
> //add Signature Appearance from
image path 
> 
> void PdfSignatureField::CreateSignatureAppearance(const
char *n2Path) 
> { 
> if( !m_pWidget->HasAppearanceStream() ) 
> { 
>
PdfRect rect(0,0,
m_pWidget->GetRect().GetWidth(),m_pWidget->GetRect().GetHeight()); 
>
PdfXObject xobjAPN(rect,m_pObject->GetOwner()); 
> PdfXObject
xobjFRM(rect,xobjAPN.GetObject()->GetOwner(),"FRM"); 
> PdfXObject
xobjN0(rect,xobjFRM.GetObject()->GetOwner(),"n0"); 
> PdfXObject
xobjN1(rect,xobjFRM.GetObject()->GetOwner(),"n1"); 
> PdfXObject
xobjN2(rect,xobjFRM.GetObject()->GetOwner(),"n2"); 
> PdfXObject
xobjN3(rect,xobjFRM.GetObject()->GetOwner(),"n3"); 
> PdfXObject
xobjN4(rect,xobjFRM.GetObject()->GetOwner(),"n4"); 
> 
> PdfImage
n2Image(rect,xobjN2.GetObject()->GetOwner(),"img"); 
>
n2Image.LoadFromPng(n2Path); 
> n2Image.SetImageChromaKeyMask(0,0,0); 
>

> //PdfImage n3Image(rect,xobjN3.GetObject()->GetOwner(),"img"); 
>
//n3Image.LoadFromPng("e:\x.png"); 
>
//n3Image.SetImageChromaKeyMask(0,0,0); 
> 
> PdfPainter painter; 
> 
>
painter.SetPage(&xobjAPN); 
>
painter.DrawXObject(rect.GetLeft(),rect.GetBottom(),&xobjFRM); 
>
painter.FinishPage(); 
> 
> painter.SetPage(&xobjFRM); 
>
painter.DrawXObject(rect.GetLeft(),rect.GetBottom(),&xobjN0); 
>
painter.DrawXObject(rect.GetLeft(),rect.GetBottom(),&xobjN1); 
>
painter.DrawXObject(rect.GetLeft(),rect.GetBottom(),&xobjN2); 
>
painter.DrawXObject(rect.GetLeft(),rect.GetBottom(),&xobjN3); 
>
painter.DrawXObject(rect.GetLeft(),rect.GetBottom(),&xobjN4); 
>
painter.FinishPage(); 
> 
> painter.SetPage( &xobjN2 ); 
>
painter.DrawImage(rect.GetLeft(),rect.GetBottom(),&n2Image,rect.GetWidth()
/ n2Image.GetWidth(),rect.GetHeight() / n2Image.GetHeight() ); 
>
painter.FinishPage(); 
> 
> PdfDictionary dictN; 
> 
> dictN.AddKey(
"N", xobjAPN.GetObject()->Reference() ); 
>
m_pWidget->GetObject()->GetDictionary().AddKey( "AP", dictN ); 
>
//m_pWidget->SetAppearanceStream(&xobjImage); 
>
//pWidget->SetAppearanceStream( &xObj ); 
> } 
> 
> } 
> 
> void
CreateSimpleForm( PdfPage* pPage, PdfDocument* pDoc, const PdfData
&signatureData,const char *imagePath ) 
> { 
> 
> PdfSignatureField
signField( pPage, PdfRect( 50000 * CONVERSION_CONSTANT, 50000 *
CONVERSION_CONSTANT, 
> 50000 * CONVERSION_CONSTANT, 50000 *
CONVERSION_CONSTANT ), pDoc ); 
> srand(unsigned(time(0))); 
> #define
random(x) (rand()%x) 
> int rad = random(10000); 
> char
signaFieldName[20]; 
> sprintf(signaFieldName,"signatureName%d",rad); 
>
signField.SetFieldName(signaFieldName); 
>
signField.SetSignature(signatureData); 
>
signField.SetSignatureReason("I agree"); 
> // Set time of signing 
>
signField.SetSignatureDate( PdfDate() ); 
> 
> //add the Signature
Appearance 
> signField.CreateSignatureAppearance(imagePath); 
> 
> } 
>

> int main( int argc, char* argv[] ) 
> { 
> testCxImage(); 
> return
0; 
> 
> PdfFileInputStream fileStream("e:\hello.pdf"); 
> char *streamf
= new char[fileStream.GetFileLength()]; 
> size_t org =
fileStream.GetFileLength(); 
> fileStream.Read(streamf,org); 
> PdfPage*
pPage; 
> PdfPainter painter; 
> PdfSignOutputDevice signer("e:\hello -
123.pdf"); 
> char dbuff[1024] = {0}; 
> int rlen = 0; 
> 
>
signer.Write(streamf,org); 
> 
> if (!signer.HasSignaturePosition()) 
>
{ 
> signer.SetSignatureSize(1024 * 8); 
> } 
> 
> PdfMemDocument
memSigner; 
> memSigner.Load(streamf,org); 
> 
> PdfAcroForm *pAcroForm
= memSigner.GetAcroForm(ePdfCreateObject,
PdfAcroForm::ePdfAcroFormDefaultAppearance_None); 
> pPage =
memSigner.GetPage(0); 
> 
> CreateSimpleForm(pPage, &memSigner,
*signer.GetSignatureBeacon(),"e:\鼓楼地税.png"); 
>
memSigner.Write(&signer); 
> 
> //size_t ss = signer.GetSignatureSize();

> //size_t sp = signer.GetLength(); 
> // Check if position of
signature was found 
> if(signer.HasSignaturePosition()) { 
> // Adjust
ByteRange for signature 
> signer.AdjustByteRange(); 
> // Read data for
signature and count it 
> // We have to seek at the beginning of the
file 
> signer.Seek(0); 
> char buff[1024]; 
> DWORD len; 
> DWORD
inSize = 0; 
> char * data; 
> BYTE * pSignature = NULL; 
> DWORD size;

> while( (len = signer.ReadForSignature(buff, 1024))>0 ) 
> { 
> inSize
= inSize + len; 
> } 
> signer.Seek(0); 
> data = new char[inSize]; 
>
len = signer.ReadForSignature(data,inSize); 
> 
> SignMessage((BYTE
*)data,inSize,pSignature,size); 
> char sig_buf[1024] = {0}; 
> if (data
!= NULL) 
> { 
> delete data; 
> data = NULL; 
> } 
> 
>
signer.SetSignature(PdfData((char *)pSignature,size)); 
> if (pSignature
!= NULL) 
> { 
> free(pSignature); 
> pSignature = NULL; 
> } 
> } 
>
signer.Flush(); 
> 
> return 0; 
> } 
> 
> -------------------------
>

> Ethan.Lee.W 
> 
>
------------------------------------------------------------------------------
>
Own the Future-Intel® Level Up Game Demo Contest 2013
> Rise to
greatness in Intel's independent game demo contest.
> Compete for
recognition, cash, and the chance to get your game 
> on Steam. $5K
grand prize plus 10 genre and skill prizes. 
> Submit your demo by
6/6/13. http://p.sf.net/sfu/intel_levelupd2d [1]
> 
>
_______________________________________________
> Podofo-users mailing
list
> [email protected]
>
https://lists.sourceforge.net/lists/listinfo/podofo-users [2]



Links:
------
[1] http://p.sf.net/sfu/intel_levelupd2d
[2]
https://lists.sourceforge.net/lists/listinfo/podofo-users
------------------------------------------------------------------------------
Own the Future-Intel® Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to