> Is there any static method or even global function in podofo's public API
> that check if a file is a PDF one ?
I made one that conflicts with the last commit.
--
Pierre Marchand
Index: tools/podofoimpose/pdftranslator.cpp
===================================================================
--- tools/podofoimpose/pdftranslator.cpp (révision 651)
+++ tools/podofoimpose/pdftranslator.cpp (copie de travail)
@@ -73,6 +73,23 @@
return true;
}
+bool PdfTranslator::checkIsPDF(std::string path)
+{
+ ifstream in ( path.c_str(), ifstream::in );
+ if (!in.good())
+ throw runtime_error("setSource() failed to open input file");
+
+ const int magicBufferLen = 5;
+ char magicBuffer[magicBufferLen ];
+ in.read(magicBuffer, magicBufferLen );
+ std::string magic( magicBuffer , magicBufferLen );
+
+ if(magic.find("%PDF") < 5)
+ return true;
+
+ return false;
+}
+
PdfTranslator::PdfTranslator(double sp)
{
sourceDoc = 0;
@@ -82,16 +99,7 @@
void PdfTranslator::setSource ( const std::string & source )
{
- ifstream in ( source.c_str(), ifstream::in );
- if (!in.good())
- throw runtime_error("setSource() failed to open input file");
-
- const int magicBufferLen = 5;
- char magicBuffer[magicBufferLen ];
- in.read(magicBuffer, magicBufferLen );
- std::string magic( magicBuffer , magicBufferLen );
-
- if(magic.find("%PDF") < 5)//it is a PDF file (I hope)
+ if(checkIsPDF(source))
{
in.close();
inFilePath = source;
Index: tools/podofoimpose/pdftranslator.h
===================================================================
--- tools/podofoimpose/pdftranslator.h (révision 651)
+++ tools/podofoimpose/pdftranslator.h (copie de travail)
@@ -85,6 +85,7 @@
double destHeight;
int maxPageDest;
+ bool checkIsPDF(std::string path);
void drawLine(double x, double y, double xx, double yy, std::ostringstream & a );
void signature(double x , double y, int sheet, const std::vector<int> & pages, std::ostringstream & a );
int pageRange(int plan, int sheet , int pagesInBooklet, int numBooklet); // much more a macro !
-------------------------------------------------------------------------
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
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users