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 · 0 comments
Open

Unable to parse text from a valid pdf #363

carlosrafp opened this issue Sep 9, 2024 · 0 comments

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

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

No branches or pull requests

1 participant