| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2005 Dominik Seichter <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <iostream> |
| 7 |
#include "pdfinfo.h" |
| 8 |
|
| 9 |
#include <cstdlib> |
| 10 |
#include <cstdio> |
| 11 |
|
| 12 |
using namespace std; |
| 13 |
using namespace PoDoFo; |
| 14 |
|
| 15 |
void print_help() |
| 16 |
{ |
| 17 |
printf("Usage: podofopdfinfo [DCPON] [inputfile] \n\n"); |
| 18 |
printf(" This tool displays information about the PDF file\n"); |
| 19 |
printf(" according to format instruction (if not provided, displays all).\n"); |
| 20 |
printf(" D displays Document Info.\n"); |
| 21 |
printf(" C displays Classic Metadata.\n"); |
| 22 |
printf(" P displays Page Info.\n"); |
| 23 |
printf(" O displays Outlines.\n"); |
| 24 |
printf(" N displays Names.\n"); |
| 25 |
printf("\nPoDoFo Version: %s\n\n", PODOFO_VERSION_STRING); |
| 26 |
} |
| 27 |
|
| 28 |
struct Format |
| 29 |
{ |
| 30 |
bool document; // D |
| 31 |
bool classic; // C |
| 32 |
bool pages; // P |
| 33 |
bool outlines; // O |
| 34 |
bool names; // N |
| 35 |
Format() :document(true), classic(true), pages(true), outlines(true), names(true) {} |
| 36 |
}; |
| 37 |
|
| 38 |
Format ParseFormat(const string_view& fs) |
| 39 |
{ |
| 40 |
Format ret; |
| 41 |
|
| 42 |
if (fs.find('D') == string_view::npos) |
| 43 |
ret.document = false; |
| 44 |
|
| 45 |
if (fs.find('C') == string_view::npos) |
| 46 |
ret.classic = false; |
| 47 |
|
| 48 |
if (fs.find('P') == string_view::npos) |
| 49 |
ret.pages = false; |
| 50 |
|
| 51 |
if (fs.find('O') == string_view::npos) |
| 52 |
ret.outlines = false; |
| 53 |
|
| 54 |
if (fs.find('N') == string_view::npos) |
| 55 |
ret.names = false; |
| 56 |
|
| 57 |
return ret; |
| 58 |
} |
| 59 |
|
| 60 |
void Main(const cspan<string_view>& args) |
| 61 |
{ |
| 62 |
#if 1 |
| 63 |
PdfCommon::SetMaxLoggingSeverity(PdfLogSeverity::None); // turn it off to better view the output from this app! |
| 64 |
#endif |
| 65 |
|
| 66 |
if (args.size() < 2 || args.size() > 3) |
| 67 |
{ |
| 68 |
print_help(); |
| 69 |
exit(-1); |
| 70 |
} |
| 71 |
|
| 72 |
string_view input; |
| 73 |
Format format; |
| 74 |
string filepath; |
| 75 |
|
| 76 |
if (args.size() == 2) |
| 77 |
{ |
| 78 |
input = args[1]; |
| 79 |
} |
| 80 |
else if (args.size() == 3) |
| 81 |
{ |
| 82 |
input = args[2]; |
| 83 |
format = ParseFormat(args[1]); |
| 84 |
} |
| 85 |
|
| 86 |
if (!input.empty()) |
| 87 |
filepath = input; |
| 88 |
//else leave empty |
| 89 |
|
| 90 |
PdfInfoHelper info(filepath); |
| 91 |
|
| 92 |
if (format.document) |
| 93 |
{ |
| 94 |
cout << "Document Info" << endl; |
| 95 |
cout << "-------------" << endl; |
| 96 |
cout << "\tFile: " << filepath << endl; |
| 97 |
info.OutputDocumentInfo(cout); |
| 98 |
cout << endl; |
| 99 |
} |
| 100 |
|
| 101 |
if (format.classic) |
| 102 |
{ |
| 103 |
cout << "Classic Metadata" << endl; |
| 104 |
cout << "----------------" << endl; |
| 105 |
info.OutputInfoDict(cout); |
| 106 |
cout << endl; |
| 107 |
} |
| 108 |
|
| 109 |
if (format.pages) |
| 110 |
{ |
| 111 |
cout << "Page Info" << endl; |
| 112 |
cout << "---------" << endl; |
| 113 |
info.OutputPageInfo(cout); |
| 114 |
} |
| 115 |
|
| 116 |
if (format.outlines) |
| 117 |
{ |
| 118 |
cout << "Outlines" << endl; |
| 119 |
cout << "--------" << endl; |
| 120 |
info.OutputOutlines(cout); |
| 121 |
} |
| 122 |
|
| 123 |
if (format.names) |
| 124 |
{ |
| 125 |
cout << "Names" << endl; |
| 126 |
cout << "-----" << endl; |
| 127 |
info.OutputNames(cout); |
| 128 |
} |
| 129 |
} |