| 1 | /** |
| 2 | * SPDX-FileCopyrightText: (C) 2009 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: podofoincrementalupdates [-e N out.pdf] file.pdf\n\n"); |
| 17 | printf(" This tool prints information of incremental updates to file.pdf.\n"); |
| 18 | printf(" By default the number of incremental updates will be printed.\n"); |
| 19 | printf(" -e N out.pdf\n"); |
| 20 | printf(" Extract the Nth update from file.pdf and write it to out.pdf.\n"); |
| 21 | printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING); |
| 22 | } |
| 23 | |
| 24 | int get_info(const string_view& filepath) |
| 25 | { |
| 26 | int updateCount = 0; |
| 27 | |
| 28 | PdfIndirectObjectList objects; |
| 29 | PdfParser parser(objects); |
| 30 | |
| 31 | FileStreamDevice input(filepath); |
| 32 | parser.Parse(input); |
| 33 | |
| 34 | updateCount = parser.GetNumberOfIncrementalUpdates(); |
| 35 | |
| 36 | printf("%s\t=\t%i\t(Number of incremental updates)\n", filepath.data(), updateCount); |
| 37 | |
| 38 | return updateCount; |
| 39 | } |
| 40 | |
| 41 | void extract(const string_view& filePath, int requestedNthUpdate, const string_view& outputFilePath) |
| 42 | { |
| 43 | (void)filePath; |
| 44 | (void)requestedNthUpdate; |
| 45 | (void)outputFilePath; |
| 46 | // TODO |
| 47 | fprintf(stderr, "extraction is not implemented\n"); |
| 48 | exit(-2); |
| 49 | } |
| 50 | |
| 51 | void Main(const cspan<string_view>& args) |
| 52 | { |
| 53 | PdfCommon::SetMaxLoggingSeverity(PdfLogSeverity::None); |
| 54 | |
| 55 | if (args.size() != 2 && args.size() != 5) |
| 56 | { |
| 57 | print_help(); |
| 58 | exit(-1); |
| 59 | } |
| 60 | |
| 61 | string_view inputPath; |
| 62 | string_view outputPath; |
| 63 | int requestedNthUpdate = -1; |
| 64 | |
| 65 | if (args.size() == 2) |
| 66 | { |
| 67 | inputPath = args[1]; |
| 68 | get_info(inputPath); |
| 69 | } |
| 70 | else if (args.size() == 5) |
| 71 | { |
| 72 | requestedNthUpdate = strtol(args[2].data(), NULL, 10); |
| 73 | outputPath = args[3]; |
| 74 | inputPath = args[4]; |
| 75 | extract(inputPath, requestedNthUpdate, outputPath); |
| 76 | } |
| 77 | } |