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

192
Views
Can't send pdf file to PDF-Dist in React

I upload a pdf file in the html . I need to send it to a javascript library called "pdf-dist". It extracts text from PDF files. I can't send the PDF file from as parameter to the pdf dist function It always returns an error: format is wrong

The error log:

"Unhandled Rejection (Error): Invalid PDF binary data: either typed array, string, or array-like object is expected in the data property."

I've already tried e.target.value, e.target.files, e.target.files[0] Always returns "format error"

the code:


import React, { Component, useState } from 'react';

import "./upload.css"
const pdfjs = require("pdfjs-dist/legacy/build/pdf")

async function getContent(src){
    const doc = await pdfjs.getDocument(src).promise
    const page = await doc.getPage(1)
    return await page.getTextContent()
}

async function getItems(src){
    const content = await getContent(src)
    const items = content.items.map((item) => {
        alert(item.str)
    })
    return items
}

function App (){    

    //const [file, setFile] = useState(null)

    var texto = "kkkkkk teste"

    async function showFile (e) {
        e.preventDefault()
        console.log(e.target.files[0])
        getItems(e.target.files[0])
    }

    return (
        <div className = "upload">
            <h1 className="uploadText">UPLOAD PDF</h1>
            <h1 className="uploadText">{texto}</h1>
            <div className="uploadWrapper">
                <div className="uploadTop">
                    <input
                        type="file"
                        accept='.pdf'
                        onChange={(e) => showFile(e)}
                    />
                </div>
            </div>
        </div>
    )
    
}

export default App;

about 4 years ago · Juan Pablo Isaza
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!