Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to test this app? #1

Closed
htrxuan opened this issue Jan 24, 2018 · 1 comment
Closed

how to test this app? #1

htrxuan opened this issue Jan 24, 2018 · 1 comment

Comments

@htrxuan
Copy link

htrxuan commented Jan 24, 2018

Hi,

could you give me requirement for this app? how could I test this?

@pbock
Copy link
Owner

pbock commented Jan 24, 2018

You need to extract the data from the Aztec code on your ticket and then pass them into TicketParser.parse(). How you do that is up to you, you just need a parser that supports binary data. I've had success with zxing and built a Node.js wrapper around it, ZebraCrossing. It takes an image as input and tries to decode any 1d-/2d-barcodes in it.

If you have the original PDF that contained the ticket, then there's a single-purpose module for extracting the Aztec code from that too: ot-aztec-extract.

It’s been over a year since I last touched this code, but if you have the original ticket PDFs, you should be able to stick these three modules together quite neatly like this:

const extractAztec = require('ot-aztec-extract');
const zxing = require('zebra-crossing');
const TicketParser = require('ticket-parser');
const iconv = require('iconv-lite');
const fs = require('fs');

function read(pdfPath) {
  return extractAztec(fs.readFileSync(pdfPath))
  .then(png => zxing.read(png, { pureBarcode: true }))
  .then(data => iconv.encode(data.raw, 'latin1'))
  .then(TicketParser.parse)
}

I’ve been meaning to combine that into a proper npm module for ages and never got around to it. (I don’t remember why iconv is in there, but it’s something to do with the fact that the data is binary.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants