Dr-NULL / CMD-Printer

A NPM module for print PDF in Windows
MIT License
3 stars 2 forks source link

Paper format/size #7

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi, I was wondering is it possible to provide format/slize of the paper in numeric value, like for example I want it to be 55x35mm?

Dr-NULL commented 3 years ago

About this module...

This module it's a wrapper for Sumatra PDF, you can check the available options through command line args here. Answering your question, Sumatra PDF doesn't provide a way to set a custom size of the paper. However, if you don't assign a predefined paper size, the module will use the paper size of the current PDF document do you want to print.

How to handle this limitation...

In my case for example, I have an app that prints labels with a size of 150mm x 100mm, or in some cases, a size of 100mm x 100mm. This labels are printed by Zebra label printers. Those printers have its own paper configuration (through the printer driver settings), and in my case only need to set the document and the printer, and some other parameters to adjust the content to the paper setted into the printer driver configuration panel:

import { CmdPrinter, CmdQueue } from 'cmd-printer';

export async function main(): Promise<void> {
  // Get the Zebra printer
  const printers = await CmdPrinter.getAll();
  const printer = printers.find(x => x.name === 'Zebra Printer 01');

  // Create a new CmdQueue instance
  const cmd = new CmdQueue({
    printTo: printer,      // Set the zebra printer here
    scale: 'fit'           // Size adjustment
  });

  // Print the document
  await cmd.print([ './test/100x150.pdf' ]);
}

Summary

If you need to print a document with a custom paper size: