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

Method parse_file

src/parse/parser.h:209–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207 }
208
209 bool parser::parse_file(std::string inp_filename,
210 std::string out_filename,
211 nlohmann::json& task,
212 pdflib::decode_config page_config,
213 bool pretty_print)
214 {
215 pdflib::pdf_timings pdf_timings;
216 document_decoder = std::make_shared<pdflib::pdf_decoder<pdflib::DOCUMENT>>(pdf_timings);
217
218 if(pdf_timings.has_key("fonts-initialisation"))
219 {
220 LOG_S(ERROR) << "fonts are not initialised";
221 return false;
222 }
223
224 std::optional<std::string> password;
225 if (input_file["password"].is_null())
226 {
227 password = std::nullopt;
228 }
229 else
230 {
231 password = input_file["password"];
232 }
233 if(not document_decoder->process_document_from_file(inp_filename, password))
234 {
235 LOG_S(ERROR) << "aborting the parse of file "<< inp_filename;
236 return false;
237 }
238
239 if(task.count("page-numbers")==0)
240 {
241 document_decoder->decode_document(page_config);
242 }
243 else
244 {
245 std::vector<int> page_numbers = task["page-numbers"];
246 document_decoder->decode_document(page_numbers, page_config);
247 }
248
249 // Build the output JSON from the typed API
250 nlohmann::json json_document;
251
252 json_document["info"]["filename"] = inp_filename;
253 json_document["info"]["#-pages"] = document_decoder->get_number_of_pages();
254 json_document["annotations"] = document_decoder->get_annotations();
255
256 nlohmann::json json_pages = nlohmann::json::array({});
257 for(int p = 0; p < document_decoder->get_number_of_pages(); ++p)
258 {
259 if(document_decoder->has_page_decoder(p))
260 {
261 auto page_dec = document_decoder->get_page_decoder(p);
262 json_pages.push_back(page_dec->get(page_config));
263 }
264 }
265 json_document["pages"] = json_pages;
266

Callers

nothing calls this directly

Calls 11

has_keyMethod · 0.80
is_nullMethod · 0.80
decode_documentMethod · 0.80
get_number_of_pagesMethod · 0.80
has_page_decoderMethod · 0.80
countMethod · 0.45
get_annotationsMethod · 0.45
get_page_decoderMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected