/** * SPDX-FileCopyrightText: (C) 2010 Ian Ashley * SPDX-License-Identifier: GPL-2.0-or-later */ #include #include #include #include using namespace std; using namespace PoDoFo; void Main(const cspan& args) { PdfCommon::SetMaxLoggingSeverity(PdfLogSeverity::None); PdfMemDocument document; if (args.size() != 3) { cerr << "Usage: podofogc \n" << " Performs garbage collection on a PDF file.\n" << " All objects that are not reachable from within\n" << " the trailer are deleted.\n" << flush; return; } cerr << "Parsing " << args[1] << " ... (this might take a while)" << flush; bool incorrectPw = false; string pw; do { try { document.Load(args[1], pw); } catch (PdfError& e) { if (e.GetCode() == PdfErrorCode::InvalidPassword) { cout << endl << "Password :"; std::getline(cin, pw); cout << endl; // try to continue with the new password incorrectPw = true; } else { throw; } } } while (incorrectPw); cerr << " done" << endl; cerr << "Writing..." << flush; document.Save(args[2]); cerr << "Parsed and wrote successfully" << endl; }