edabg / jsprintsetup

JSPrintSetup Firefox addon
Mozilla Public License 2.0
76 stars 39 forks source link

Printed image not scaling / resizing to label - too small portrait, too large landscape #33

Open bogal opened 7 years ago

bogal commented 7 years ago

I have a strange issue printing labels with a ZDesigner GK420d.

The following is my print code:

function doPrint(imageFrame){
  jsPrintSetup.setPrinter('ZDesigner GK420d');
  jsPrintSetup.setOption('orientation', jsPrintSetup.kLandscapeOrientation);
  //jsPrintSetup.setOption('orientation', jsPrintSetup.kPortraitOrientation);
  jsPrintSetup.setPaperSizeUnit(jsPrintSetup.kPaperSizeMillimeters);

  jsPrintSetup.definePaperSize(101,101, "Custom", "Custom_Paper", "Custom PAPER",108,297,jsPrintSetup.kPaperSizeMillimeters);
  jsPrintSetup.setPaperSizeData(101);
  jsPrintSetup.setOption('shrinkToFit', 1);

  // set empty page header
  jsPrintSetup.setOption('headerStrLeft','');
  jsPrintSetup.setOption('headerStrCenter', '');
  jsPrintSetup.setOption('headerStrRight', '');
  // set empty page footer
  jsPrintSetup.setOption('footerStrLeft', '');
  jsPrintSetup.setOption('footerStrCenter', '');
  jsPrintSetup.setOption('footerStrRight', '');

  jsPrintSetup.clearSilentPrint();
  jsPrintSetup.setOption('printSilent', 1);
  jsPrintSetup.printWindow(imageFrame);
  jsPrintSetup.setOption('printSilent', 0);
}

I'm running this on windows 10. Looking in my FF(50.0.2)'s about:config, i found the paper sizes for this printer, and entered them as a custom paper size. However, this is different from the actual size of the labels i am trying to print on, which are 100mm width x 150mm height. I have tried changing the above custom paper size to this, but it makes no difference to the actual print out.

When i print the image in portrait, it fits on one label but is very small, and when i set the paper orientation to landscape, the font is huge and prints on many labels. It's almost like it is having problems shrinking the image to fit.

Any suggestions on what else to try would be appreciated.

bogal commented 7 years ago

I should add, that: console.log(jsPrintSetup.getPaperMeasure()); outputs:

{"PD":null,"W":50.8,"H":76.2}

I'm not sure what these measurements are, as they are neither defined in about:config, or realistic paper sizes for this printer.

Also in the above example, the parameter "imageFrame" for the doPrint function is an iframe with the src set to a .png image - and i am calling jsPrintSetup.printWindow(imageFrame) to print just this.

mitkola commented 7 years ago
  1. You have to define custom paper size under Windows.
  2. Obtain value of paper_data for your custom paper form. The simplest way is to print manually on this form and then inspect value of print.printer_ZDesigner_GK420d.print_paper_data. For linux toy have to obtain value of print.printer_ZDesigner_GK420d.print_paper_name
  3. The your code for define paper size will looks like:
    // ...
    var paper_data = 105; // For windows value obtained in step 2 for print.printer_ZDesigner_GK420d.print_paper_data
    var paper_name = 'Custom'; // For linux value of print.printer_ZDesigner_GK420d.print_paper_name
    jsPrintSetup.definePaperSize(101,paper_data, paper_name, "Custom_Paper", "Custom PAPER",108,297,jsPrintSetup.kPaperSizeMillimeters);
    jsPrintSetup.setPaperSizeData(101);
    // ...

    I hope that this will solve the problem.

bogal commented 7 years ago

Thanks for the reply.

I was able to workaround this, by setting the paper sizes in about:config.

print.printer_ZDesigner_GK420d.print_paper_height; 150.00 print.printer_ZDesigner_GK420d.print_paper_width;100.00

I removed the scaling function, and call to custom paper size, and it printed perfectly. Will this cause any problems long-term? I'm assuming that because the paper size is now hard-coded it will only work on this specific paper? Not so much a problem here as this printer is a dedicated dispatch label printer, that is always going to be using the same size paper.

I would prefer a proper fix though, so followed your steps: 1) Created the custom paper size in windows ok (i'm developing on win10 machine, to be run on web linux server - will that still work?). Cannot set the custom paper size in the print software as the instructions suggest, as i get a different screen to the default win10 printer settings (assuming it was installed with the drivers). There is no option to set the default paper size.

bogal commented 7 years ago

print1

mitkola commented 7 years ago

You have to create form in 'Print server properties'

bogal commented 7 years ago

Yes i created the form ok. But i can't do step 2 of that tutorial "Select the new custom paper size in the printer software" - where i select the new paper size as the printer default. Without doing that, print.printer_ZDesigner_GK420d.print_paper_data is -1 and print.printer_ZDesigner_GK420d.print_paper_name is an empty string.

mitkola commented 7 years ago

Form Firefox print manually print to this printer selecting your custom form. image

bogal commented 7 years ago

Even using the PDFCreator as the printer, it is not allowing me to choose the custom paper size. See pics attached, as well as a screenshot of print server settings showing the custom form present. print2

mitkola commented 7 years ago

Microsoft Print to PDF doesn't support custom paper size. I have used PDFCreator. If you want to define custom paper size for Microsoft Print to PDF here is how to do. But actually you have to print on your ZDesigner_GK420d printer.

bogal commented 7 years ago

My bad. Installed PDFCreator, followed the instructions above using native print and setting the paper size to my custom form, and the paper_name and paper_data are in about:config are now as follows: print.printer_PDFCreator.print_paper_data = 121 print.printer_PDFCreator.print_paper_name; (empty string)

h0jeZvgoxFepBQ2C commented 7 years ago

So it's not enought to call the method definePaperSizeData and I always have to create them in the windows settings? Why do I have to call the definePaperSizeData then?

I'm also struggling already several hours to get it working and it's really confusing...