| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2010 Ian Ashley <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <iostream> |
| 7 |
#include <cstdlib> |
| 8 |
#include <cstdio> |
| 9 |
|
| 10 |
#include <podofo/podofo.h> |
| 11 |
|
| 12 |
using namespace std; |
| 13 |
using namespace PoDoFo; |
| 14 |
|
| 15 |
void Main(const cspan<string_view>& args) |
| 16 |
{ |
| 17 |
PdfCommon::SetMaxLoggingSeverity(PdfLogSeverity::None); |
| 18 |
|
| 19 |
PdfMemDocument document; |
| 20 |
|
| 21 |
if (args.size() != 3) |
| 22 |
{ |
| 23 |
cerr << "Usage: podofogc <input_filename> <output_filename>\n" |
| 24 |
<< " Performs garbage collection on a PDF file.\n" |
| 25 |
<< " All objects that are not reachable from within\n" |
| 26 |
<< " the trailer are deleted.\n" |
| 27 |
<< flush; |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
cerr << "Parsing " << args[1] << " ... (this might take a while)" |
| 32 |
<< flush; |
| 33 |
|
| 34 |
bool incorrectPw = false; |
| 35 |
string pw; |
| 36 |
do |
| 37 |
{ |
| 38 |
try |
| 39 |
{ |
| 40 |
document.Load(args[1], pw); |
| 41 |
} |
| 42 |
catch (PdfError& e) |
| 43 |
{ |
| 44 |
if (e.GetCode() == PdfErrorCode::InvalidPassword) |
| 45 |
{ |
| 46 |
cout << endl << "Password :"; |
| 47 |
std::getline(cin, pw); |
| 48 |
cout << endl; |
| 49 |
|
| 50 |
// try to continue with the new password |
| 51 |
incorrectPw = true; |
| 52 |
} |
| 53 |
else |
| 54 |
{ |
| 55 |
throw; |
| 56 |
} |
| 57 |
} |
| 58 |
} while (incorrectPw); |
| 59 |
|
| 60 |
cerr << " done" << endl; |
| 61 |
|
| 62 |
cerr << "Writing..." << flush; |
| 63 |
document.Save(args[2]); |
| 64 |
|
| 65 |
cerr << "Parsed and wrote successfully" << endl; |
| 66 |
} |