modesty / modesty/pdf2json

Unable to parse text from a valid pdf

Open
#363 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help-wanted: type3-font not-supported
Dominant language
Java
Stars
2.2k
Forks
394
Avg merge
3d 5h
Merged PRs (30d)
7

Description

Trying to extract the text from the following pdf gives wrong characters.

input pdf:
laudo.pdf

Fragment extracted from the 1st page:
䴀䄀吀䔀刀䤀䄀䰀 ⴀ 匀䄀一䜀唀䔀
䠀䔀䴀伀䜀刀䄀䴀䄀

Code used to extract text:
async function extractPageTextsFromPdf(pdfBuffer: Buffer): Promise<string[]> { const pdfParser = new PDFParser(null, true, ''); function decodePdfPageTexts(texts: Text[]) { return decodeURIComponent( texts.map((t) =>t.R.map((tt) => tt.T).join(' ')).join(' ') ); } const texts: Promise<string[]> = new Promise((resolve, reject) => { pdfParser.on('pdfParser_dataReady', (pdfData) => { const { Pages: pages } = pdfData; const tx = pages.map((p) => p.Texts).map(decodePdfPageTexts); resolve(tx); }); pdfParser.on('pdfParser_dataError', (errData) => { reject(errData.parserError); }); pdfParser.parseBuffer(pdfBuffer); }); return texts; }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the problem with the linked laudo.pdf using extractPageTextsFromPdf and the PDFParser parseBuffer entry point. Trace how page text and character encodings are represented before decodePdfPageTexts; done means the extracted first-page text is readable rather than the shown incorrect characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.