1

I'm trying to print a single-page PDF with a specific dimension onto a label (or ribbon). Let's say for this example the dimensions are 0.63" wide and 11.81" long.

I'm using QZ Tray to handle printing directly from the browser.

The problem

The printer has default size parameters defined on the computer, and if I try printing my PDF directly using QZ Tray's pixel printing the size of the PDF is ignored, and instead the "default" size is used.

I switched to QZ Tray's raw printing in EPL format with the q and Q parameters added to the command so the size of the media is adjusted.

This results in the following data being used for printing:

const data = [
    '\nN\n',
    'q' + pdfData.width.dots + '\n',
    'Q' + pdfData.height.dots + ',00\n',
    {
        type: 'raw', format: 'pdf', flavor: 'base64', data: pdfData.file,
        options: { language: "EPL" }
    },
    '\nP1\n';
];

qz.print(config, data).catch(function (e) {
    console.error(e);
});

Even though I can now successfully override the printer's default size, it appears the PDF is not aligned correctly anymore (an empty label is "printed" instead).

There have been some instances in which I did see something being printed "outside" of the label (I'm printing using thermal transfer).

I have also played around with the pageSize options for the PDF in the printer configuration, but these seem to have no impact, or at least result in the same blank label being printed.

Question

Is there a way in QZ Tray which allows me to ensure the PDF is alligned propperly on the label. Or is there another way to approach this issue?

Note

The PDF is the only content on the label and the page size is the exact size that the label should be.

Martie
  • 280
  • 1
  • 8
  • For starters, a set dimension (e.g. 4x6) and a set PDF should be used to reduce the question's complexity to simply "How can I fit this PDF onto this label, but with EPL commands". The fact that you're using Laravel and Snappy seem to be superfluous to the issue of sizing. – tresf Aug 19 '23 at 17:16
  • Question: Can you explain why you're using [`RAW`](https://qz.io/docs/raw) for this task instead of [`PIXEL`](https://qz.io/docs/pixel)? Pixel will handle the page size much more gracefully. I would also strongly encourage calibrating the printer to the paper size prior to printing anything. Last, I would generate a PDF at the exact size of the paper and experiment with `Render width` and `Render height` here: https://demo.qz.io/. See also https://qz.io/docs/raw#epl-1 `pageWidth` and `pageHeight`. – tresf Aug 19 '23 at 17:19
  • Thanks for the question @tresf. I initially tried working with pixel printing but ran into the same issue. The reason for switching to raw was the ability to add the q and Q params. Also it’s true the method of generating the PDF doesn’t matter much for this question. I will edit it to simplify it a bit – Martie Aug 19 '23 at 17:56
  • If the PDF doesn't fit with `scaleContent=true` the most likely causes is lack of calibration. Most printers have a Windows driver that can do this automatically, some have a sequence of button presses that can do the same. There are also some QZ Tray issues with landscape printing on Mac if that's your platform, so baselining on Linux or Windows may be necessary. – tresf Aug 19 '23 at 18:17
  • 1
    @tresf thanks again for getting back to me. I've updated the question with some additional relevant info and removed the "fluff". As mentioned in the question now, I did try playing around with the `pageWidth` and `pageHeight` options, but without any luck. The scale content also seems to have no effect on the printed result. I'm on Ubuntu, but will see if there is any difference in the results on a Windows machine. Also as far as calibration goes, is this stored within the printer? I've connected it to an existing app on an android tablet from which it prints correctly in various sizes. – Martie Aug 19 '23 at 20:57
  • `scaleContent=true` is for `Pixel` printing only. I would expect this to work just fine out of the box for most printers. If you're using `Raw` printing mode, this parameter is ignored. `Raw` mode should be unaffected by OS, but `Pixel` mode can be affected by the OS. Linux will use the CUPS drivers, but you will need to use the EPL2 drivers. In regards to calibration, [most older EPL printers can be calibrated with button presses](https://youtu.be/mD7nrSsyp7s?t=38) so that you do not need the driver, but procedure will vary depending on the hardware. – tresf Aug 19 '23 at 22:52
  • In regards to the `pageWidth` and `pageHeight` being ignored, I would recommend that you try to provide them in pixels. This is poorly documented and we need to improve this behavior, but `PDFRenderer.renderImage()` takes a scale factor and we [calculate this based on the percentage difference between the PDF's bounding box and the values provided](https://github.com/qzind/tray/blob/045a9bcdd46a4516191107e0367cae86b2c15656/src/qz/printer/action/PrintRaw.java#L199-L209) so AFAIR there's no units involved, which differs from the Pixel implementation of the same parameter. – tresf Aug 19 '23 at 22:55
  • `0.63" wide and 11.81"` This is a 16mm x 300mm label? Hmm... That's pretty narrow, the printer might not know what the top left corner is. Can you email me a copy of it? `tres@qz.io`? – tresf Aug 19 '23 at 23:07
  • @tresf, thanks again for getting back to me! Just to be sure, would pageWidth and pageHeight use a 72 dpi resolution afterwards? I'm asking as it's important that the ribbon would have the exact length that is specified, so in order to correctly convert the millimeters to pixels I believe the DPI would be important. It's a thin ribbon, but with other software it prints correctly. I will also send you a few copies of the generated PDFs and some pictures of the results. Also good to note I will have a meeting with the dev of the other software sometime soon to get their input. – Martie Aug 21 '23 at 07:50
  • I believe the PDF defaults to 72 dpi, according to this: https://stackoverflow.com/questions/21520015 – tresf Aug 21 '23 at 12:37

0 Answers0