Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Node.JS JavaScript fetching PDF contents prints PDFPage Formats instead

I'm trying to fetch the text contents of the first page of a PDF file using NPM node module 'PDF-lib'.

However when I fetch the contents and print the results, I instead get an array of data that looks something like below;

Could you please help me spot the problem?

Thanks in advance!

The results I get after printing look like this. What I want to fetch are the actual text contents of the PDF page.

PDFPage {

fontSize: 24,

fontColor: { type: 'RGB', red: 0, green: 0, blue: 0 },

lineHeight: 24,

x: 0,

y: 0,

node: PDFPageLeaf {

dict: Map(8) {

[PDFName] => [PDFName],

[PDFName] => [PDFRef],

[PDFName] => [PDFDict],

[PDFName] => [PDFArray],

[PDFName] => [PDFRef],

[PDFName] => [PDFDict],

[PDFName] => [PDFName],

[PDFName] => [PDFNumber]

},

...

...

...

The Code:


const { resolve } = require('path');
const { PDFDocument } = require('pdf-lib'); // Library for reading PDF file
const fs = require('fs');

async function readDataset() {

    try { 

        // Get PDF Page
        const content = await PDFDocument.load(fs.readFileSync(resolve(`./app/assets/pdfs/np.pdf`)));

        // Get page contents
        const contentPages = content.getPages();

        let pageContent = contentPages[0];

        // Return data found on first page
        return pageContent;
    }

    catch (err) { 
        return err;
    }
    
}

// Read data from dataset
let dataset = await readDataset();

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Not generally possible at present (2021 ) with this library see current Limitations this info is also on the npm page at https://www.npmjs.com/package/pdf-lib#limitations

#1

pdf-lib can extract the content of text fields (see PDFTextField.getText), but it cannot extract plain text on a page outside of a form field. This is a difficult feature to implement, but it is within the scope of this library and may be added to pdf-lib in the future. See #93, #137, #177, #329, and #380.

For future visitors always check the link above for current status.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!