Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pdfjs get all the text present

import PDFJS from "pdfjs-dist";
import PDFJSWorker from "pdfjs-dist/build/pdf.worker.js"; // add this to fit 2.3.0

PDFJS.disableTextLayer = true;
PDFJS.disableWorker = true; // not availaible anymore since 2.3.0 (see imports)

const getPageText = async (pdf: Pdf, pageNo: number) => {
  const page = await pdf.getPage(pageNo);
  const tokenizedText = await page.getTextContent();
  const pageText = tokenizedText.items.map(token => token.str).join("");
  return pageText;
};

/* see example of a PDFSource below */
export const getPDFText = async (source: PDFSource): Promise<string> => {
  Object.assign(window, {pdfjsWorker: PDFJSWorker}); // added to fit 2.3.0
  const pdf: Pdf = await PDFJS.getDocument(source).promise;
  const maxPages = pdf.numPages;
  const pageTextPromises = [];
  for (let pageNo = 1; pageNo <= maxPages; pageNo += 1) {
    pageTextPromises.push(getPageText(pdf, pageNo));
  }
  const pageTexts = await Promise.all(pageTextPromises);
  return pageTexts.join(" ");
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: search an array with regex javascript indexOf 
Javascript :: pdf.js extract text 
Javascript :: javascript clone object 
Javascript :: How to use AlpineJS with Laravel Mix 
Javascript :: js add query param 
Javascript :: nodejs global 
Javascript :: save file javascript 
Javascript :: sequelize transaction config 
Javascript :: === javascript 
Javascript :: material icon button angular 
Javascript :: Random number given a range js 
Javascript :: alpine js open outside div 
Javascript :: javascript print to console 
Javascript :: react-data-table-component cell action stack overflow 
Javascript :: how to code a discord bot in javascript 
Javascript :: JavaScript setTimeout js function timer 
Javascript :: else return 
Javascript :: get url from string javascript 
Javascript :: append string javascript 
Javascript :: nodejs express flash message 
Javascript :: add word in string in javascript 
Javascript :: $out in mongodb 
Javascript :: setTimeout(() = { console.log(i);}, 100); 
Javascript :: JavaScript Initialize Variables 
Javascript :: await fetch parameters 
Javascript :: how to map through an object javascript 
Javascript :: address 
Javascript :: how to return json data from mvc controller to view 
Javascript :: javascript fetch api 
Javascript :: for loop on array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =