1.0.0 • Published 8 years ago

hp-webscan v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

hp-webscan

npm version npm

Package to scan documents with the HP webscan unofficial API

Uses calls from printer's web interface (port 80)

  • ES6 (needs Node.JS >= 6.0.0)
  • Choose format and size
  • Fast
  • Error(s) management
  • Only ≈65 lines

Usage

Please see notes before using this module

Installation

npm install hp-webscan

Scan a document

const Webscan = require("hp-webscan");
const fs = require("fs");

var ws = new Webscan("printer's hostname/ip", 1);

// See type, fmt, size definitions below
ws.scan({ type: 4, fmt: 1, size: 2 }, (data, error) => {
  if(error) {
    console.log("an error occured: " + error.code)
  }
  else {
    // Do whatever you want with the binary data
    // Here we write the document on disk using fs
    fs.writeFile(__dirname + "/scan.jpg", data, "binary", (err) => {
      if(err) {
        return console.log(err);
      }
      else console.log("Document successfully scanned and saved!")
    });
  }
})

Get a preview (much faster than a scan)

ws.preview({ type: 2 }, (data, error) => {
  if(error) {
    console.log("an error occured: " + error.code)
  }
  else {
    // Do whatever you want with data
    // Here we write the document on disk
    fs.writeFile(__dirname + "/preview.jpg", data, "binary", (err) => {
      if(err) {
        return console.log(err);
      }
    });
  }
})

Types

IDValue
1Text (black and white)
2Picture (black and white)
3Drawing (colored)
4Picture (colored)

Sizes

IDValue
0Letter
1Executive
2A4(8.27x11.69")‎
310.16x15.24 cm. (4x6")‎
412.7X17.78 cm. (5x7")
57.6x12.7 cm. (3x5")‎
67.6x7.6 cm. (3x3")‎

Formats

IDValue
1image/jpeg
2application/pdf (crashes my printer)

Error codes

CodeMeaning
WS_STATUSWebinterface can't be reached or version incompatible
GET_SCANCannot download the scanned document
GET_PREVIEWCannot download the previewed document

Notes

  • I'm NOT affiliated with Hewlett Packard/HP or one of its branches
  • You could combine this module with node-tesseract to make a powerful ocr-scanner
  • This module may not work on another version than mine, I have this one: mine
NameValue
Product NameHP Deskjet F4500 series
Product ModelNumber CB755B
Product SerialNumber CN9CIB218Z05H5
Service ID20090
Printer ID4
Firmware VersionMPxxFN0937AR