跳到正文
DEV Community· Ayush Mishra·· 58 分鐘前AI 評分55

PDF to Text Extractor 如何將網頁上的 PDF 轉成 RAG 文本,毋須編寫爬蟲

Turn every PDF on a web page into text for RAG, without writing a crawler

AI 導讀

Ayush Mishra 分享如何用自建的 Apify Actor「PDF to Text Extractor」,找出網頁上的 PDF 並抽取文字供 RAG 使用,毋須編寫爬蟲。

正文

Ayush Mishra

Say a site has a "Reports" page with 30 PDFs and you want their text in a vector store. The slow part is rarely the parsing. It is finding the links, downloading the files and not paying twice for the same file. Here is how I do it with an Apify Actor I built, PDF to Text Extractor.

1. Start the run

Create a free Apify account if you do not have one, open the Actor and put the page that links to the PDFs into Web pages to scan for PDF links. Leave sameDomainOnly on so you only get the site's own files. Set maxPdfs to 20 for a first look and pick an output format: per_page, document or markdown.

2. Read the inventory row first

The first dataset row has type: "inventory". found is every PDF link seen on the page, queued is how many this run takes, and links shows the source page and link text of each. It is free. If found is 34 and queued is 20, you know a full run is about 34 PDFs before you pay for it.

3. Use the document rows

Each PDF is one type: "document" row with status, pageCount, wordCount, the text and metadata. Filter on status == "ok" before indexing. A PDF linked from several pages is extracted once; the copies come back as free duplicate rows.

4. Handle scanned files

Pages with no text layer are listed in needsOcrPages. The Actor does not do OCR, and a scanned-only file is free, so send those to an OCR tool of your choice and keep the rest.

Limits

No OCR, no table extraction, and multi-column layouts can interleave. PDFs behind a login are not found. robots.txt is honored by default.

Price is $3 per 1,000 PDFs of up to 100 pages. I built this Actor, so take the comparison with that in mind.

來源:DEV Community · dev.to