Debian Codegraph @

podofo/tools/podofoimpose/podofoimpose.cpp

raw
1 /**
2 * SPDX-FileCopyrightText: (C) 2007 Pierre Marchand <[email protected]>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include "pdftranslator.h"
7
8 #include <cstdlib>
9 #include <iostream>
10 #include <string>
11 #include <cstdio>
12
13 using namespace std;
14 using namespace PoDoFo;
15 using namespace PoDoFo::Impose;
16
17 struct _params
18 {
19 string executablePath;
20 string inFilePath;
21 string outFilePath;
22 string planFilePath;
23 PlanReader planReader;
24 } params;
25
26 void usage()
27 {
28 cerr << "Usage : " << params.executablePath << " Input Output Plan [Interpreter]" << endl;
29 cerr << "***" << endl;
30 cerr << "\tInput is a PDF file or a file which contains a list of PDF file paths" << endl << endl;
31 cerr << "\tOutput will be a PDF file" << endl << endl;
32 cerr << "\tPlan is an imposition plan file" << endl << endl;
33 cerr << "\t[Interpreter] Can be \"native\" (default value) or \"lua\"" << endl << endl;
34 cerr << "PoDoFo Version: " << PODOFO_VERSION_STRING << endl << endl;
35 }
36
37 void parseCommandLine(const cspan<string_view>& args)
38 {
39 params.executablePath = args[0];
40
41 if (args.size() < 4)
42 {
43 usage();
44 exit(-1);
45 }
46
47 params.inFilePath = args[1];
48 params.outFilePath = args[2];
49 params.planFilePath = args[3];
50 params.planReader = PlanReader::Legacy;
51 if (args.size() >= 5)
52 {
53 string native("native");
54 string lua("lua");
55 string interpreter(args[4]);
56
57 if (!interpreter.compare(native))
58 params.planReader = PlanReader::Legacy;
59 else if (!interpreter.compare(lua))
60 params.planReader = PlanReader::Lua;
61 }
62 }
63
64 /**
65 * Return values:
66 *
67 * 0 : success
68 * 1 : bad command line arguments
69 */
70 void Main(const cspan<string_view>& args)
71 {
72 #if 0
73 PdfError::EnableDebug(false);
74 PdfError::EnableLogging(false);
75 #endif
76 parseCommandLine(args);
77
78 cerr << "Source : " << params.inFilePath << endl;
79 cerr << "Target : " << params.outFilePath << endl;
80 cerr << "Plan : " << params.planFilePath << endl;
81
82
83 PdfTranslator* translator = new PdfTranslator;
84
85 translator->setSource(params.inFilePath);
86 translator->setTarget(params.outFilePath);
87 translator->loadPlan(params.planFilePath, params.planReader);
88
89 translator->impose();
90 }