| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2006 Dominik Seichter <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <podofo/podofo.h> |
| 7 |
|
| 8 |
#include <cstdlib> |
| 9 |
#include <cstdio> |
| 10 |
|
| 11 |
using namespace std; |
| 12 |
using namespace PoDoFo; |
| 13 |
|
| 14 |
void print_help() |
| 15 |
{ |
| 16 |
printf("Usage: podofomerge [inputfile1] [inputfile2] [outputfile]\n\n"); |
| 17 |
printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING); |
| 18 |
} |
| 19 |
|
| 20 |
void merge(const string_view input1Path, const string_view input2Path, const string_view outputPath) |
| 21 |
{ |
| 22 |
printf("Reading file: %s\n", input1Path.data()); |
| 23 |
PdfMemDocument input1; |
| 24 |
input1.Load(input1Path); |
| 25 |
printf("Reading file: %s\n", input2Path.data()); |
| 26 |
PdfMemDocument input2; |
| 27 |
input2.Load(input2Path); |
| 28 |
|
| 29 |
printf("Appending %i pages on a document with %i pages.\n", input2.GetPages().GetCount(), input1.GetPages().GetCount()); |
| 30 |
input1.GetPages().AppendDocumentPages(input2); |
| 31 |
|
| 32 |
// we are going to bookmark the insertions |
| 33 |
// using destinations - also adding each as a NamedDest |
| 34 |
/* |
| 35 |
PdfDestination p1Dest( input1.GetPage(0) ); |
| 36 |
input1.AddNamedDestination( p1Dest, std::string("Input1") ); |
| 37 |
PdfOutlines* bMarks = input1.GetOutlines(); |
| 38 |
PdfOutlineItem* bmRoot = bMarks->CreateRoot( "Merged Document" ); |
| 39 |
PdfOutlineItem* child1 = bmRoot->CreateChild( pszInput1, p1Dest ); |
| 40 |
PdfDestination p2Dest( input1.GetPage(pgCount) ); |
| 41 |
input1.AddNamedDestination( p2Dest, std::string("Input2") ); |
| 42 |
child1->CreateNext( pszInput2, p2Dest ); |
| 43 |
*/ |
| 44 |
|
| 45 |
#ifdef TEST_FULL_SCREEN |
| 46 |
input1.GetCatalog().SetUseFullScreen(); |
| 47 |
#else |
| 48 |
input1.GetCatalog().SetPageMode(PdfPageMode::UseOutlines); |
| 49 |
input1.GetCatalog().SetHideToolbar(); |
| 50 |
input1.GetCatalog().SetPageLayout(PdfPageLayout::TwoColumnLeft); |
| 51 |
#endif |
| 52 |
|
| 53 |
printf("Writing file: %s\n", outputPath.data()); |
| 54 |
input1.Save(outputPath); |
| 55 |
} |
| 56 |
|
| 57 |
void Main(const cspan<string_view>& args) |
| 58 |
{ |
| 59 |
if (args.size() != 4) |
| 60 |
{ |
| 61 |
print_help(); |
| 62 |
exit(-1); |
| 63 |
} |
| 64 |
|
| 65 |
auto input1Path = args[1]; |
| 66 |
auto input2Path = args[2]; |
| 67 |
auto outputPath = args[3]; |
| 68 |
|
| 69 |
merge(input1Path, input2Path, outputPath); |
| 70 |
} |