Hi,
I dabbled a bit with podofomerge and changed it so it is possible to
merge multiple documents, not just two. Don't know if that is useful to
anyone else.
Please double check the code in the patch for correctness since I rarely
code in C/C++.
Kind regards,
Chris
diff --git a/podofo/trunk/tools/podofomerge/podofomerge.cpp b/podofo/trunk/tools/podofomerge/podofomerge.cpp
index fa14a6b92..db6e3e285 100644
--- a/podofo/trunk/tools/podofomerge/podofomerge.cpp
+++ b/podofo/trunk/tools/podofomerge/podofomerge.cpp
@@ -31,24 +31,29 @@ using namespace PoDoFo;
void print_help()
{
- printf("Usage: podofomerge [inputfile1] [inputfile2] [outputfile]\n\n");
+ printf("Usage: podofomerge [inputfile1] [inputfile2] [inputfile..n] [outputfile]\n\n");
printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING);
}
-void merge( const char* pszInput1, const char* pszInput2, const char* pszOutput )
+void merge( char* pszInputArr[], const int nInputFileCount, const char* pszOutput )
{
+ const char* pszInput1 = pszInputArr[0];
printf("Reading file: %s\n", pszInput1 );
PdfMemDocument input1( pszInput1 );
- printf("Reading file: %s\n", pszInput2 );
- PdfMemDocument input2( pszInput2 );
+
+ for (int i = 1; i < nInputFileCount; ++i )
+ {
+ printf("Reading file: %s\n", pszInputArr[i] );
+ PdfMemDocument inputPdf( pszInputArr[i] );
// #define TEST_ONLY_SOME_PAGES
#ifdef TEST_ONLY_SOME_PAGES
- input1.InsertPages( input2, 1, 2 );
+ input1.InsertPages( inputPdf, 1, 2 );
#else
- printf("Appending %i pages on a document with %i pages.\n", input2.GetPageCount(), input1.GetPageCount() );
- input1.Append( input2 );
+ printf("Appending %i pages on a document with %i pages.\n", inputPdf.GetPageCount(), input1.GetPageCount() );
+ input1.Append( inputPdf );
#endif
+ }
// we are going to bookmark the insertions
// using destinations - also adding each as a NamedDest
@@ -62,7 +67,7 @@ void merge( const char* pszInput1, const char* pszInput2, const char* pszOutput
input1.AddNamedDestination( p2Dest, std::string("Input2") );
child1->CreateNext( pszInput2, p2Dest );
*/
-
+
#ifdef TEST_FULL_SCREEN
input1.SetUseFullScreen();
#else
@@ -77,22 +82,23 @@ void merge( const char* pszInput1, const char* pszInput2, const char* pszOutput
int main( int argc, char* argv[] )
{
- char* pszInput1;
- char* pszInput2;
+ char* pszInputArr[argc-2];
char* pszOutput;
- if( argc != 4 )
+ if( argc < 4 )
{
print_help();
exit( -1 );
}
- pszInput1 = argv[1];
- pszInput2 = argv[2];
- pszOutput = argv[3];
+ for (int i = 1; i < argc-1; ++i)
+ {
+ pszInputArr[i-1] = argv[i];
+ }
+ pszOutput = argv[argc-1];
try {
- merge( pszInput1, pszInput2, pszOutput );
+ merge( pszInputArr, argc-2, pszOutput );
} catch( PdfError & e ) {
fprintf( stderr, "Error %i occurred!\n", e.GetError() );
e.PrintErrorMsg();
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users