| 106 | } |
| 107 | |
| 108 | int main(int argc, char* argv[]) { |
| 109 | int orig_argc = argc; |
| 110 | |
| 111 | // Initialize loguru |
| 112 | loguru::init(argc, argv); |
| 113 | |
| 114 | try { |
| 115 | cxxopts::Options options("PDFProcessor", "A program to process PDF files or configuration files"); |
| 116 | |
| 117 | // Define the options |
| 118 | options.add_options() |
| 119 | ("i,input", "Input PDF file", cxxopts::value<std::string>()) |
| 120 | ("c,config", "Config file", cxxopts::value<std::string>()) |
| 121 | ("create-config", "Create config file", cxxopts::value<std::string>()) |
| 122 | ("p,page", "Pages to process (default: -1 for all)", cxxopts::value<int>()->default_value("-1")) |
| 123 | ("page-range", "Inclusive page range to process, e.g. 10-20", cxxopts::value<std::string>()) |
| 124 | ("password", "Password for accessing encrypted, password-protected files", cxxopts::value<std::string>()) |
| 125 | ("o,output", "Output file", cxxopts::value<std::string>()) |
| 126 | ("export-images", "Export images to directory", cxxopts::value<std::string>()) |
| 127 | ("print-cells", "Print cells to stdout [char, word, line, all] (default: none)", cxxopts::value<std::string>()) |
| 128 | ("l,loglevel", "Log level [error, warning, info]", cxxopts::value<std::string>()) |
| 129 | ("h,help", "Print usage") |
| 130 | |
| 131 | // ---- decode_config ---- |
| 132 | ("page-boundary", "Page boundary [crop_box, media_box, ...] (default: crop_box)", cxxopts::value<std::string>()) |
| 133 | ("do-sanitization", "Run post-parse sanitization (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 134 | ("keep-char-cells", "Keep individual character cells (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 135 | ("keep-shapes", "Keep shape items (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 136 | ("keep-bitmaps", "Keep bitmap items (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 137 | ("max-num-lines", "Cap on number of lines per page (-1 = no cap)", cxxopts::value<int>()) |
| 138 | ("max-num-bitmaps", "Cap on number of bitmaps per page (-1 = no cap)", cxxopts::value<int>()) |
| 139 | ("create-word-cells", "Build word-level cells (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 140 | ("create-line-cells", "Build line-level cells (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 141 | ("enforce-same-font", "Require same font within a word/line cell (default: true)", cxxopts::value<bool>()->implicit_value("true")) |
| 142 | ("horizontal-cell-tolerance", "Horizontal merge tolerance (default: 1.0)", cxxopts::value<double>()) |
| 143 | ("word-space-factor", "Space-width factor for word merging (default: 0.33)", cxxopts::value<double>()) |
| 144 | ("line-space-factor", "Space-width factor for line merging (default: 1.0)", cxxopts::value<double>()) |
| 145 | ("line-space-factor-with-space", "Space-width factor for line merging with space (default: 0.33)", cxxopts::value<double>()) |
| 146 | ("keep-glyphs", "Keep unmapped GLYPH<...> tokens (default: false)", cxxopts::value<bool>()->implicit_value("true")) |
| 147 | ("keep-qpdf-warnings", "Emit QPDF warnings (default: false)", cxxopts::value<bool>()->implicit_value("true")) |
| 148 | ("populate-json", "Populate JSON objects during decode (default: false)", cxxopts::value<bool>()->implicit_value("true")); |
| 149 | |
| 150 | // Parse command line arguments |
| 151 | auto result = options.parse(argc, argv); |
| 152 | |
| 153 | // Check if either input or config file is provided (mandatory) |
| 154 | if (orig_argc == 1) { |
| 155 | LOG_F(ERROR, "Either input (-i) or config (-c) must be specified."); |
| 156 | LOG_F(INFO, "%s", options.help().c_str()); |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | std::string level = "warning"; |
| 161 | if (result.count("loglevel")) { |
| 162 | level = result["loglevel"].as<std::string>(); |
| 163 | |
| 164 | // Convert the string to lowercase |
| 165 | std::transform(level.begin(), level.end(), level.begin(), [](unsigned char c) { |
nothing calls this directly
no test coverage detected