thiagoelg / node-printer

Native node.js printer
125 stars 75 forks source link

Ink Annotations malformed at time of print. #70

Open maxvinten opened 1 year ago

maxvinten commented 1 year ago

Hiya!

Written a bulk printing app that crunches images and PDFs into a single PDF, saves the output, then slings the output at a printer.

The file goes together fine, the annotations are representative of the original PDF files on the generated PDF. But here's where the trouble begins... At the very end of the script I make a call to the printing function and the file that comes out looks a little different. The annotations (only seen this on the "ink" annotations, like when you draw on a file in the edge browser) appear to have "shifted" up and to the right, while still retaining their edge bounding box. The result looks like the bottom left corner of the original annotation positioned up and to the right with the top and right side missing as if it's been cropped. Interestingly, printing the file from the windows print dialog works fine, and the annotations aren't changed.

The printers I'm working with only like RAW files, not PDF, so RAW it is... I've looked everywhere to see if there's a way to bake annotations, but it seems it require external dependencies like imagemagick, so I was hoping I could reach out here.

// Call this function with the inputs to print a file
  function printFile(filePath, printerName) {
    // Read the file, in the context of this code, it's the combined PDF
    const file = fs.readFileSync(filePath);

    // Define print options
    const printOptions = {
      data: file,
      printer: printerName,
      type: 'RAW',
    };

    // Print the file with the above options
    return new Promise((resolve, reject) => {
      printer.printDirect({
        ...printOptions,
        success: function (jobID) {
        console.log(`Combined PDF sent to printer with job ID: ${jobID}`);
        resolve(jobID);
      },
      error: function (err) {
        console.log(err);
        reject(err);
      }
    });
  });
}