PdfParser will throw an exception with error code ePdfError_NoPdfFile it the 
file is no valid PDF file. Though if you open the PDF using PdfMemDocument 
you will get this exception which you could catch.

A static method is not available, but could easily be added. I am not sure if 
it is needed as you most likely will want to open the PDF with PdfMemDocument 
anyways. So a static method would first parse the PDF file to see if it is 
valid and than again in PdfMemDocument to read it. I think it is better to 
parse only once in PdfMemDocument and throw an exception if the file is 
invalid.

best regards,
        Dom


Am Friday 21 September 2007 schrieb Pierre Marchand:
> Le jeudi 20 septembre 2007 21:34, Craig Ringer a écrit :
> > > Modified: podofo/trunk/tools/podofoimpose/pdftranslator.cpp
> > > ===================================================================
> > > --- podofo/trunk/tools/podofoimpose/pdftranslator.cpp     2007-09-19
> > > 15:19:00 UTC (rev 649) +++
> > > podofo/trunk/tools/podofoimpose/pdftranslator.cpp 2007-09-20 15:48:24
> > > UTC (rev 650) @@ -85,10 +85,62 @@
> > >
> > >  void PdfTranslator::setSource ( const std::string & source )
> > >  {
> > > -    inFilePath = source;
> > > -    sourceDoc = new PdfMemDocument ( inFilePath.c_str() ); // must
> > > succeed or throw +        ifstream in ( source.c_str(), ifstream::in );
> > > + if (!in.good())
> > > +         throw runtime_error("setSource() failed to open input file");
> > > +
> > > + char *magicBuffer = new char [5];
> > > + in.read(magicBuffer, 5);
> > > + std::string magic( magicBuffer , 5 );
> >
> > This is a memory leak, as magicBuffer is never freed. It's not a big
> > issue but should be fixed. Eliminating the dynamic memory allocation in
> > favour of a stack-based static buffer would be preferable - overrun is
> > not a risk since read() checks length limits.
>
> Is there any static method or even global function in podofo's public API
> that check if a file is a PDF one ?
>
> --
> Pierre Marchand
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> 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: pgpzjgSP8P71B.pgp
Description: PGP signature

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to