oups, I sent  the wrong diff. Here is the good.
-- 
Pierre Marchand
Index: tools/podofoimpose/pdftranslator.cpp
===================================================================
--- tools/podofoimpose/pdftranslator.cpp	(révision 651)
+++ tools/podofoimpose/pdftranslator.cpp	(copie de travail)
@@ -73,6 +73,24 @@
     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  );
+	
+	in.close();
+	if(magic.find("%PDF") < 5)
+		return true;
+	
+	return false;
+}
+
 PdfTranslator::PdfTranslator(double sp)
 {
     sourceDoc = 0;
@@ -82,24 +100,19 @@
 
 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;
     		sourceDoc = new PdfMemDocument ( inFilePath.c_str() ); // must succeed or throw
 	}
 	else // it has to be a list of PDF files
 	{
-		in.seekg(0);
+		
+		ifstream in ( source.c_str(), ifstream::in );
+		if (!in.good())
+			throw runtime_error("setSource() failed to open input file");
+		
 		std::vector<std::string> fileList;
 		char *filenameBuffer = new char[1000];
 		do
@@ -125,6 +138,7 @@
 			multiSource.push_back(*ms);
 			}
 		}
+		delete filenameBuffer;
 	}
 }
 
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to