packages/markitdown/src/markitdown/converters/_pdf_converter.pyPDF 沒有語意結構,所以這檔最「工程導向」:先嘗試用 pdfplumber 抽表格,
再與 pdfminer 的文字抽取互補;最後有一段 post-process 把「MasterFormat 風格的部分編號」
(.1、.2…)與下一行合併,避免被版面切碎。
.1 等部分編號與後續文字合併回同一行。MasterFormat 文件用 .1 The intent of this RFP... 這種部分編號;
pdfminer 常把它切成 .1 換行再接內文。此函數用 regex 偵測並黏回。
輸出 | c1 | c2 | + | --- | --- | 分隔列,處理格內換行與空值。
對非標準表格的 PDF,從 pdfplumber page 的 word 物件按座標(行/列)重建內容, 補救 pdfminer 的抽取順序問題。
先嘗試 pdfplumber page.extract_tables();對「無邊框表格」則退回
_extract_tables_from_words——用 word 的 x/y 座標聚類成欄與列。
convert 用 pdfplumber.open 逐頁處理:對每頁先試表格抽取、再疊加
文字抽取(兩者都會跑),最後跑 _merge_partial_numbering_lines 後處理。掃描版(無文字層)
或複雜版面是已知弱點——官方建議高品質抽取改用 Azure Content Understanding。