MCPcopy Create free account
hub / github.com/docling-project/docling-parse / main

Function main

app/analyse.cpp:255–462  ·  view source on GitHub ↗

----------------------------------------------------------------- main -----------------------------------------------------------------

Source from the content-addressed store, hash-verified

253// main
254// -----------------------------------------------------------------
255int main(int argc, char* argv[])
256{
257 int orig_argc = argc;
258 loguru::init(argc, argv);
259 loguru::g_stderr_verbosity = loguru::Verbosity_ERROR;
260
261 try
262 {
263 cxxopts::Options options("analyse",
264 "Find pages with null raw_stream_data and "
265 "decoded_stream_data in PDF image XObjects");
266
267 options.add_options()
268 ("i,input", "Input PDF file or directory", cxxopts::value<std::string>())
269 ("o,output", "Output JSON file (optional)", cxxopts::value<std::string>())
270 ("r,render-dir", "Directory containing rendered page PNG images", cxxopts::value<std::string>())
271 ("p,page", "Page number to analyse (0-based, default: -1 for all pages)",
272 cxxopts::value<int>()->default_value("-1"))
273 ("export-bitmaps", "Export decoded bitmap payloads encountered on each page",
274 cxxopts::value<bool>()->implicit_value("true"))
275 ("export-page-pdf", "Export each rendered page as a sibling PDF",
276 cxxopts::value<bool>()->implicit_value("true"))
277 ("l,loglevel", "Log level [error, warning, info]", cxxopts::value<std::string>())
278 ("h,help", "Print usage");
279
280 auto result = options.parse(argc, argv);
281
282 if (orig_argc == 1 or result.count("help"))
283 {
284 std::cout << options.help() << "\n";
285 return result.count("help") ? 0 : 1;
286 }
287
288 if (result.count("loglevel"))
289 {
290 std::string lvl = result["loglevel"].as<std::string>();
291 std::transform(lvl.begin(), lvl.end(), lvl.begin(),
292 [](unsigned char c) { return std::tolower(c); });
293 if (lvl == "info") { loguru::g_stderr_verbosity = loguru::Verbosity_INFO; }
294 else if (lvl == "warning") { loguru::g_stderr_verbosity = loguru::Verbosity_WARNING; }
295 else if (lvl == "error") { loguru::g_stderr_verbosity = loguru::Verbosity_ERROR; }
296 }
297
298 if (not result.count("input"))
299 {
300 LOG_S(ERROR) << "-i/--input is required";
301 return 1;
302 }
303
304 std::filesystem::path input_path = result["input"].as<std::string>();
305 std::vector<std::filesystem::path> pdf_paths = collect_pdfs(input_path);
306 int target_page = result["page"].as<int>();
307
308 std::string render_dir;
309 if (result.count("render-dir"))
310 {
311 render_dir = result["render-dir"].as<std::string>();
312 }

Callers

nothing calls this directly

Calls 9

collect_pdfsFunction · 0.85
analyse_pdfFunction · 0.85
parseMethod · 0.45
countMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected