Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse text from a valid pdf #363

Open
carlosrafp opened this issue Sep 9, 2024 · 1 comment
Open

Unable to parse text from a valid pdf #363

carlosrafp opened this issue Sep 9, 2024 · 1 comment

Comments

@carlosrafp
Copy link

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; }

@modesty
Copy link
Owner

modesty commented Dec 30, 2024

The text's font, T3Font_0, is Type 3 font and custom encoding, not supported, same as issue #377
Two options to move forward:

  1. submit PR to support type 3 font rendering in canvas.js
  2. recreate the PDF with standard TrueType font and standard encoding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@modesty @carlosrafp and others