Code Monkey home page Code Monkey logo

pdf-lecture's Introduction

pdf-lecture

Javascript cross-platform module to extract texts from PDFs.

version downloads

Similar Packages

Installation

npm install pdf-lecture

Basic Usage - Local Files

var path = require("path");
var fs = require("fs");
var filePath = path.join(__dirname, "..your path");
var PDF = require("pdf-lecture");

PDF(filePath).then((data) => {
   console.log(data.numpages)
   console.log(data.text)
   console.log(data.pageTextArray)
});

Exception Handling

const fs = require('fs');

var filePath = path.join(__dirname, "..your path");
var PDF = require("pdf-lecture");

PDF(filePath).then(function(data) {
	// use data
})
.catch(function(error){
	// handle exceptions
})
// default render callback
function render_page(pageData) {
  let render_options = {
    normalizeWhitespace: false,
    disableCombineTextItems: false,
  };

  return pageData.getTextContent(render_options).then(function (textContent) {
    let lastY,
      text = "";
    for (let item of textContent.items) {
      if (lastY == item.transform[5] || !lastY) {
        text += item.str;
      } else {
        text += "\n" + item.str;
      }
      lastY = item.transform[5];
    }
    return text;
  });
}

let options = {
    pagerender: render_page
}

let dataBuffer = fs.readFileSync('path to PDF file...');

pdf(dataBuffer,options).then(function(data) {
	//use new format
});

Options

const DEFAULT_OPTIONS = {
	// internal page parser callback
	// you can set this option, if you need another format except raw text
	pagerender: render_page,
	
	// max page number to parse
	max: 0,
	
	//check https://mozilla.github.io/pdf.js/getting_started/
	version: 'v1.10.100'
}

pagerender (callback)

If you need another format except raw text.

max (number)

Max number of page to parse. If the value is less than or equal to 0, parser renders all pages.

version (string, pdf.js version)

check pdf.js

  • 'default'
  • 'v1.9.426'
  • 'v1.10.100'
  • 'v1.10.88'
  • 'v2.0.550'

default version is v1.10.100
mozilla.github.io/pdf.js

Submitting an Issue

If you find a bug or a mistake, you can help by submitting an issue to Github Repository

License

[MIT licensed]

pdf-lecture's People

Contributors

dulajkavinda avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.