Hi,

You do not need the second call to load after SetPassword, as any call to 
SetPassword will continue the previous load.

Please see the example code in test/ParserTest/ParserTest.cpp. It uses 
PdfParser directly instead of PdfMemDocument, but the usage for loading files 
is the same.

Best regards,
        Dom

Am Freitag 05 März 2010 schrieb Michael Marsella:
> Hi Dominik,
> 
> I just encountered the same issue, so I grabbed the latest source from
> the trunk, and I am still having issues.  Maybe I missed something, but
> looking at the code, I am unsure how this could work.
> 
> using the sample code from the initial poster we have:
> 
> PdfMemDocument *currentPodofoDocument=new PdfMemDocument();
> try
> {
>   currentPodofoDocument->Load(pdffilename);
> }
> catch(const PdfError&errorObject)
> {
>   if(errorObject.GetError() == PoDoFo::ePdfError_InvalidPassword)
>   {
>    currentPodofoDocument->SetPassword(mypassword);
>    currentPodofoDocument->Load(pdffilename);
>   }
> }
> 
> what I see happening is follows:
> 1) The first load call runs, and tosses the ePdfError_InvalidPassword
> exception. (we have not yet called InitFromParser() or InitPagesTree()
> 2) Exception is caught, we call
> currentPodofoDocument->SetPassword(mypassword); so that the
> PdfMemDocument now has the password
> 3) we attempt to call load again
> currentPodofoDocument->Load(pdffilename); here is where I think there
> may be a problem:
> 
> looking at the load call:
> 
> void PdfMemDocument::Load( const char* pszFilename )
> {
>      this->Clear();
> 
>      m_pParser = new PdfParser( PdfDocument::GetObjects() );
>      m_pParser->ParseFile( pszFilename, true );
>      InitFromParser( m_pParser );
> 
>      ...
> }
> 
> and looking at the clear call:
> 
> void PdfMemDocument::Clear()
> {
>      if( m_pEncrypt )
>      {
>          delete m_pEncrypt;
>          m_pEncrypt = NULL;
>      }
> 
>      delete m_pParser;
>      m_pParser = NULL;
> 
>      PdfDocument::Clear();
> }
> 
> It seems to me that upon the second load, PoDoFo will wipe both the
> Encrypt and Parser objects, blowing away the password we just set.
> 
> Perhaps I missed something here, or perhaps the intent is not to call
> load a second time.  Can you provide any clarification?
> 
> Cheers!
> ~Michael Marsella
> 
> On 14/01/2010 2:49 PM, Dominik Seichter wrote:
> > Hi Bjoern,
> >
> > Thanks for your very good bug report. I tested with SVN trunk and found
> > the very same issues (and even some more, including a memory leak).
> >
> > I fixed all issues I found in SVN and also added a test PDF. If you
> > upgrade to SVN trunk, your issues should be resolved.
> >
> > Best regards,
> >     Dom
> >
> > Am Freitag 08 Januar 2010 schrieb [email protected]:
> >> Hi folks,
> >>
> >> I got a problem using PdfMemDocument and wonder if this is because I
> >> miss something or there is something missing in PdfMemDocument.
> >>
> >>
> >> I made a password protected test-PDF.
> >>
> >> Concerning the documentation i found, I need to call Load(...), get an
> >> exception then call SetPassword.
> >> But here is my problem:
> >>
> >> When loading it with PdfMemDocument->Load(...), I get an exception with
> >> the error "PoDoFo::ePdfError_InvalidPassword" - thats fine.
> >> In that case I try SetPassword(...) which results in an exception
> >> because when setting the password, m_pParser of my PDFMemDocument object
> >> is still NULL although I tried loading the file before.
> >>
> >>
> >> It is NULL because in PdfMemDocument::Load(...) the m_pParser is created
> >> by
> >>
> >> m_pParser = new PdfParser( PdfDocument::GetObjects(), pszFilename, true
> >> );
> >>
> >> ...which tries to parse the document right ahead, which fails, which
> >> lets m_pParser be NULL which is a problem calling when SetPassword.
> >>
> >>
> >> I tried in PdfMemDocument::Load(...) to do the parsing after the
> >> m_pParser creation. SetPassword(...) now works, reads stuff but the
> >> pagesTree of the PDFDocument is NULL and so I am not able to access
> >> pages etc...
> >>
> >>
> >> Is there hope for me?
> >>
> >> Thanks for your time and reading this chaos. =)
> >> Bjoern
> >>
> >>
> >>
> >> A reduced code snipped:
> >>
> >> PdfMemDocument *currentPodofoDocument=new PdfMemDocument();
> >> try
> >> {
> >>   currentPodofoDocument->Load(pdffilename);
> >> }
> >> catch(const PdfError&errorObject)
> >> {
> >>   if(errorObject.GetError() == PoDoFo::ePdfError_InvalidPassword)
> >>   {
> >>    currentPodofoDocument->SetPassword(mypassword);
> >>    // currentPodofoDocument->Load(pdffilename);
> >>   }
> >> }
> >>
> >> page = currentPodofoDocument->GetPage(0);
> >>
> >>
> >>
> >> ------------------------------------------------------------------------
> >>--- --- This SF.Net email is sponsored by the Verizon Developer Community
> >> Take advantage of Verizon's best-in-class app development support A
> >> streamlined, 14 day to market process makes app distribution fast and
> >> easy Join now and get one step closer to millions of Verizon customers
> >> http://p.sf.net/sfu/verizon-dev2dev
> >> _______________________________________________
> >> Podofo-users mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/podofo-users
> >
> > -------------------------------------------------------------------------
> >----- Throughout its 18-year history, RSA Conference consistently attracts
> > the world's best and brightest in the field, creating opportunities for
> > Conference attendees to learn about information security's most important
> > issues through interactions with peers, luminaries and emerging and
> > established companies. http://p.sf.net/sfu/rsaconf-dev2dev
> >
> >
> > _______________________________________________
> > Podofo-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/podofo-users
> 


-- 
**********************************************************************
Dominik Seichter - [email protected]
KRename  - http://www.krename.net  - Powerful batch renamer for KDE
KBarcode - http://www.kbarcode.net - Barcode and label printing
PoDoFo - http://podofo.sf.net - PDF generation and parsing library
SchafKopf - http://schafkopf.berlios.de - Schafkopf, a card game,  for KDE
Alan - http://alan.sf.net - A Turing Machine in Java
**********************************************************************

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to