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

Rasterize HTML, PDFs to Raw #19

Closed
tresf opened this issue Mar 28, 2016 · 13 comments
Closed

Rasterize HTML, PDFs to Raw #19

tresf opened this issue Mar 28, 2016 · 13 comments

Comments

@tresf
Copy link
Contributor

tresf commented Mar 28, 2016

After supporting the 2.0 branch for a couple months, we've noticed an increasing amount of people trying to use Pixel printing against their raw devices for some specific cases, such as a packing slip (something that FedEx or UPS may not provide in raw format) or printing continuous feed image data (HTML) to a receipt printer.

Today, they're trying to print using the 2d printing (HTML, etc), but this often requires them to utilize a different device driver and worse, actually yields different results versus just using raw ZPL, EPL, ESCP, etc.

This enhancement is to allow raw printing to use Pixel features such as HTML, PDF, but then wrap them to the raw equivalent.

var data = [
   '^XA',
   { type: 'raw', format: 'image', flavor: 'base64' data: 'AAABBB[...]==',  options: { language: "ZPL" } },
   '^XZ'
];

Since we have the ability to rasterize PDF and HTML, there's no reason why we can't support these formats for raw printers too by rendering them, treating them as raster graphics, and then converting them to raw commands.

@tresf tresf added this to the 2.1 milestone Apr 29, 2016
@akberenz
Copy link
Member

Do we need to subset these new formats? As pdf, html, and image each have their own formats when used independantly. And this has even led to some confusion already, causing #70.

@tresf
Copy link
Contributor Author

tresf commented Jul 14, 2016

From our discussion, this will be an expansion of the API.

var data = 
['^XA', { 
   type: 'raw', format: 'image', flavor: 'file', data: 'assets/img/image_sample_bw.png', 
   options: { language: "ZPL" } 
}, '^XZ'];

@akberenz
Copy link
Member

akberenz commented Aug 3, 2016

Feature added in 9c39650
Everything looks right when printing to a file, but you'll need to verify for me on a physical device.

@tresf
Copy link
Contributor Author

tresf commented Aug 4, 2016

Everything looks right when printing to a file, but you'll need to verify for me on a physical device.

Looks pretty good. In the case of the PDF, it only takes up about 2/3rds of the height and width of a 4x6 label. How do you suggest we specify PDF size?

HTML I had a bit more control over due to the pageWidth parameter.

Also, I think it may be time to add a radio button for the language type so that we can quickly switch between (e.g.) ESCP, ZPL and EPL.

@akberenz
Copy link
Member

akberenz commented Aug 4, 2016

How do you suggest we specify PDF size?

Do you want to extend the pageWidth and pageHeight options to include pdf as well?

Also, I think it may be time to add a radio button for the language type

32ed9f1

@tresf
Copy link
Contributor Author

tresf commented Aug 4, 2016

Do you want to extend the pageWidth and pageHeight options to include pdf as well?

Sounds like a good plan. (bug was closed in error, please ignore)

@tresf tresf closed this as completed Aug 4, 2016
@tresf tresf reopened this Aug 4, 2016
@akberenz
Copy link
Member

akberenz commented Aug 8, 2016

Adjusted with 5e7afd0

@tresf
Copy link
Contributor Author

tresf commented Aug 12, 2016

For the new sample page, let's specify the following:

EPL2    ZPLII
ESCP    EPCL

ESCP is the one I'm not too sure about. I know we use ESC * technique which is clearly defined in the ESCP2 manual, but I can't find much reference to ESCP1 anywhere, perhaps @lite1979 can dig up more information.

Also, no need to show Image X and Image Y for anything except EPL2 (or CPCL, if it gets added eventually).

Last, they should both default to zero.

@tresf
Copy link
Contributor Author

tresf commented Aug 12, 2016

Some testing:

  • For our 8.5 x 11 pdf_sample.pdf sent via EPL2 render width of 812 to the Zebra printer, this feature works great
  • When testing the fourbysix.pdf to the same printer, same, render width of 812 it prints very small in upper left corner.

Any idea why the smaller PDF is printed so small?

pdf_sample.pdf

[INFO] 2016-08-12 01:40:20,248 @ qz.common.TrayManager:?
    Allowed localhost to print to Zebra LP2844 Raw
[TRACE] 2016-08-12 01:40:20,248 @ qz.utils.PrintingUtilities:?
    Waiting for processor, 0/7 already in use
[DEBUG] 2016-08-12 01:40:20,249 @ qz.utils.PrintingUtilities:?
    Using qz.printer.action.PrintRaw to print
[DEBUG] 2016-08-12 01:40:20,249 @ qz.printer.PrintServiceMatcher:?
    Searching for PrintService matching Zebra LP2844 Raw
[DEBUG] 2016-08-12 01:40:20,249 @ qz.printer.PrintServiceMatcher:?
    Found 4 printers
[DEBUG] 2016-08-12 01:40:20,272 @ qz.printer.PrintServiceMatcher:?
    Found match: Zebra LP2844 Raw
[DEBUG] 2016-08-12 01:40:20,274 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, ZDesigner_LP2844, -l]
[DEBUG] 2016-08-12 01:40:20,327 @ qz.utils.ShellUtilities:?
    Parsed default density from CUPS ZDesigner_LP2844: 203dpi
[DEBUG] 2016-08-12 01:40:20,328 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, Zebra_LP2844_Raw, -l]
[DEBUG] 2016-08-12 01:40:20,346 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, PDFwriter, -l]
[DEBUG] 2016-08-12 01:40:20,366 @ qz.utils.ShellUtilities:?
    Parsed default density from CUPS PDFwriter: 300dpi
[DEBUG] 2016-08-12 01:40:20,366 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, EpsonTM88IV, -l]
[INFO] 2016-08-12 01:40:20,563 @ qz.printer.ImageWrapper:?
    Loading BufferedImage
[INFO] 2016-08-12 01:40:20,563 @ qz.printer.ImageWrapper:?
    Dimensions: 612x792
[INFO] 2016-08-12 01:40:20,563 @ qz.printer.ImageWrapper:?
    Initializing Image Fields
[INFO] 2016-08-12 01:40:20,564 @ qz.printer.ImageWrapper:?
    Converting image to monochrome
[INFO] 2016-08-12 01:40:20,576 @ qz.printer.ImageWrapper:?
    Packing bits
[INFO] 2016-08-12 01:40:20,577 @ qz.printer.ImageWrapper:?
    Initializing Image Fields
[INFO] 2016-08-12 01:40:20,578 @ qz.printer.ImageWrapper:?
    Converting image to monochrome
[INFO] 2016-08-12 01:40:20,591 @ qz.printer.ImageWrapper:?
    Packing bits
[INFO] 2016-08-12 01:40:20,592 @ qz.printer.ImageWrapper:?
    Generating byte array
[TRACE] 2016-08-12 01:40:20,597 @ qz.printer.action.PrintRaw:?
    Sending print job to printer
[DEBUG] 2016-08-12 01:40:20,598 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@3cd5b36f
[DEBUG] 2016-08-12 01:40:20,720 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@3cd5b36f
[DEBUG] 2016-08-12 01:40:20,720 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@3cd5b36f
[DEBUG] 2016-08-12 01:40:20,720 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@3cd5b36f
[TRACE] 2016-08-12 01:40:20,720 @ qz.printer.action.PrintRaw:?
    Print job received by printer
[INFO] 2016-08-12 01:40:20,721 @ qz.utils.PrintingUtilities:?
    Printing complete
[TRACE] 2016-08-12 01:40:20,721 @ qz.utils.PrintingUtilities:?
    Returning processor back to pool

fourbysix.pdf

[DEBUG] 2016-08-12 01:42:03,365 @ qz.printer.PrintServiceMatcher:?
    Searching for PrintService matching raw
[DEBUG] 2016-08-12 01:42:03,365 @ qz.printer.PrintServiceMatcher:?
    Found 4 printers
[DEBUG] 2016-08-12 01:42:03,383 @ qz.printer.PrintServiceMatcher:?
    Found match: Zebra LP2844 Raw
[DEBUG] 2016-08-12 01:42:31,599 @ qz.ws.PrintSocketClient:?
    Message: {"call":"print","promise":{},"params":{"printer":{"name":"Zebra LP2844 Raw"},"options":{"colorType":"color","copies":"1","density":"","duplex":false,"fallbackDensity":600,"interpolation":"","jobName":"","margins":"0","orientation":"","paperThickness":"","printerTray":"","rasterize":false,"rotation":"0","scaleContent":true,"size":null,"units":"in","altPrinting":false,"encoding":"","endOfDoc":"","perSpool":"1"},"data":["\nN\n",{"type":"raw","format":"pdf","flavor":"file","data":"file:///Users/tres/tray/assets/pdf_sample.pdf","options":{"language":"EPL","x":"0","y":"0","dotDensity":"single","xmlTag":"v7:Image","pageWidth":"812","pageHeight":""}},"\nP1,1\n"]},"timestamp":1470980551597,"uid":"9uzftj"}
[WARN] 2016-08-12 01:42:31,600 @ qz.ws.PrintSocketClient:?
    Bad signature on request
[INFO] 2016-08-12 01:42:32,375 @ qz.common.TrayManager:?
    Allowed localhost to print to Zebra LP2844 Raw
[TRACE] 2016-08-12 01:42:32,375 @ qz.utils.PrintingUtilities:?
    Waiting for processor, 0/7 already in use
[DEBUG] 2016-08-12 01:42:32,376 @ qz.utils.PrintingUtilities:?
    Using qz.printer.action.PrintRaw to print
[DEBUG] 2016-08-12 01:42:32,376 @ qz.printer.PrintServiceMatcher:?
    Searching for PrintService matching Zebra LP2844 Raw
[DEBUG] 2016-08-12 01:42:32,376 @ qz.printer.PrintServiceMatcher:?
    Found 4 printers
[DEBUG] 2016-08-12 01:42:32,393 @ qz.printer.PrintServiceMatcher:?
    Found match: Zebra LP2844 Raw
[DEBUG] 2016-08-12 01:42:32,395 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, ZDesigner_LP2844, -l]
[DEBUG] 2016-08-12 01:42:32,679 @ qz.utils.ShellUtilities:?
    Parsed default density from CUPS ZDesigner_LP2844: 203dpi
[DEBUG] 2016-08-12 01:42:32,679 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, Zebra_LP2844_Raw, -l]
[DEBUG] 2016-08-12 01:42:32,698 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, PDFwriter, -l]
[DEBUG] 2016-08-12 01:42:32,717 @ qz.utils.ShellUtilities:?
    Parsed default density from CUPS PDFwriter: 300dpi
[DEBUG] 2016-08-12 01:42:32,717 @ qz.utils.ShellUtilities:?
    Executing: [lpoptions, -p, EpsonTM88IV, -l]
[INFO] 2016-08-12 01:42:33,361 @ qz.printer.ImageWrapper:?
    Loading BufferedImage
[INFO] 2016-08-12 01:42:33,362 @ qz.printer.ImageWrapper:?
    Dimensions: 288x432
[INFO] 2016-08-12 01:42:33,362 @ qz.printer.ImageWrapper:?
    Initializing Image Fields
[INFO] 2016-08-12 01:42:33,362 @ qz.printer.ImageWrapper:?
    Converting image to monochrome
[INFO] 2016-08-12 01:42:33,365 @ qz.printer.ImageWrapper:?
    Packing bits
[INFO] 2016-08-12 01:42:33,366 @ qz.printer.ImageWrapper:?
    Generating byte array
[TRACE] 2016-08-12 01:42:33,369 @ qz.printer.action.PrintRaw:?
    Sending print job to printer
[DEBUG] 2016-08-12 01:42:33,371 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@47de58a7
[DEBUG] 2016-08-12 01:42:33,676 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@47de58a7
[DEBUG] 2016-08-12 01:42:33,677 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@47de58a7
[DEBUG] 2016-08-12 01:42:33,677 @ qz.printer.action.PrintRaw:?
    PrintEvent on sun.print.UnixPrintJob@47de58a7
[TRACE] 2016-08-12 01:42:33,677 @ qz.printer.action.PrintRaw:?
    Print job received by printer
[INFO] 2016-08-12 01:42:33,677 @ qz.utils.PrintingUtilities:?
    Printing complete
[TRACE] 2016-08-12 01:42:33,677 @ qz.utils.PrintingUtilities:?
    Returning processor back to pool

@akberenz
Copy link
Member

Looks like I never had the pdf scale when the size was set..
1d4e577 should fix your issue.

@tresf
Copy link
Contributor Author

tresf commented Aug 12, 2016

@bberenz is there a good reason why the pageWidth and pageHeight are in pixels rather than units? Edit: Probably because we aren't sure of the printer DPI, huh?

@akberenz
Copy link
Member

Because we don't take in a units option for raw printing.

@tresf
Copy link
Contributor Author

tresf commented Aug 12, 2016

So, I've tested this.

  • Against 203 dpi Zebra printer, pageWidth of 812 and results are pretty good. Here's a side-by-side of desired and actual.
    image

The printable area seems to be slightly under 812 (203 * 4), so adjusting this to 800 seems to fix this in the right direction.

  • Against 180 dpi Epson receipt printer, pageWidth of 562.5 and results are dead on (or as close as they're going to get).

This looks good. We can open separate bug reports as needed. Closed via 9c39650 5e7afd0. This feature will be available in 2.1.

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

No branches or pull requests

2 participants