edabg / jsprintsetup

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

Print scale problem in jsPrintSetup 0.9.5.3 FF46 in Ubuntu #15

Open Extremal1981 opened 8 years ago

Extremal1981 commented 8 years ago

We have a problem with print scalling after update of jsPrintSetup to version 0.9.5.3 in FF46 OS Ubuntu. Everything that is sent to printing in the result has a very small size in paper. This problem occurs even when we set a particular print scalling by means of the function jsPrintSetup.setOption('scaling',100) or set shrinkToFit true When we downgrade jsPrintSetup to version 0.9.5.2, this problem disappears.

I want to pay attention that print.print_resolution value im my settings is 300, and changing of this parameter does not influence printing

mitkola commented 8 years ago

Can you send sample code that reproduce the problem? Which paper size are using?

Extremal1981 commented 8 years ago

This is my sample code. In this particular case the paper size is 55x25 and album orientation. This code is used for printing of bar code labels on Zebra printers.

jsPrint(win,defaultPrinter,55,25,0,0,0.53,0.38,95,0);

function jsPrint(win,printer,width,height,mTop,mBottom,mLeft,mRight,scalling,orient) { //orient 0 - 'kPortraitOrientation', 1 - 'kLandscapeOrientation' if (printer) { //find printer var findPrinter=''; var printers = jsPrintSetup.getPrintersList(); printers = printers.split(','); for (i=0;i!=printers.length;i++) if (printers[i].indexOf(printer)>-1) { findPrinter=printers[i];break;} if (!findPrinter) { Ext.Msg.show({title:'Error',msg:'Printer '+printer+' not found',buttons:Ext.Msg.OK});return; }; jsPrintSetup.setPrinter(findPrinter); } if (!mBottom) mBottom=0.1; if (!mLeft) mLeft=0.1; if (!mRight) mRight=0.1; if (!mBottom) mBottom=0.1; if (!width) width=210; if (!height) height=297; jsPrintSetup.setPaperSizeUnit(0); jsPrintSetup.setOption('paperWidth',width); jsPrintSetup.setOption('paperHeight',height); jsPrintSetup.setOption('headerStrCenter',''); jsPrintSetup.setOption('headerStrLeft',''); jsPrintSetup.setOption('headerStrRight',''); jsPrintSetup.setOption('footerStrCenter',''); jsPrintSetup.setOption('footerStrLeft',''); jsPrintSetup.setOption('footerStrRight',''); jsPrintSetup.setOption('footerStrRight',''); jsPrintSetup.setOption('marginTop',mTop); jsPrintSetup.setOption('marginBottom',mBottom); jsPrintSetup.setOption('marginLeft',mLeft); jsPrintSetup.setOption('marginRight',mRight); jsPrintSetup.setOption('orientation',orient); if (scalling) { jsPrintSetup.setOption('shrinkToFit',false);jsPrintSetup.setOption('scaling',scalling); } else jsPrintSetup.setOption('shrinkToFit',true); //send to print jsPrintSetup.clearSilentPrint(); jsPrintSetup.setOption('printSilent',1); jsPrintSetup.printWindow(win); win.close(); }

mitkola commented 8 years ago

There is mismatch of paper size unit you are give 0 which means in inches. 55x25 inches is very big paper and I suppose that FF 45 and 46 take different handling of this exception. I recommend to use jsPrintSetup constants.

jsPrintSetup.setPaperSizeUnit(jsPrintSetup.kPaperSizeMillimeters);

I also recommend set edge* and unwriteableMargin* options to be sure about actual printable area. There is an another important thing to consider. Print command is executed asynchronously this means that javascript execution continues after print method execution while printing is in progress. By this reason that is not recommended to close window immediately, because results are unpredictable. The simplest way is to set some enough timeout or use progress listener.

Here is working example:

function jsPrint(win,printer,width,height,mTop,mBottom,mLeft,mRight,scalling,orient) {
    //orient 0 - 'kPortraitOrientation', 1 - 'kLandscapeOrientation'
    if (printer) {
        //find printer
        var findPrinter='';
        var printers = jsPrintSetup.getPrintersList();
        printers = printers.split(',');
        for (i=0;i!=printers.length;i++) if (printers[i].indexOf(printer)>-1) { findPrinter=printers[i];break;}
        if (!findPrinter) { Ext.Msg.show({title:'Error',msg:'Printer '+printer+' not found',buttons:Ext.Msg.OK});return; };
        jsPrintSetup.setPrinter(findPrinter);
    }
    if (!mBottom) mBottom=0.1;
    if (!mLeft) mLeft=0.1;
    if (!mRight) mRight=0.1;
    if (!mBottom) mBottom=0.1;
    if (!width) width=210;
    if (!height) height=297;
    jsPrintSetup.setPaperSizeUnit(jsPrintSetup.kPaperSizeMillimeters);
    jsPrintSetup.setOption('paperWidth',width);
    jsPrintSetup.setOption('paperHeight',height);
    jsPrintSetup.setOption('headerStrCenter','');
    jsPrintSetup.setOption('headerStrLeft','');
    jsPrintSetup.setOption('headerStrRight','');
    jsPrintSetup.setOption('footerStrCenter','');
    jsPrintSetup.setOption('footerStrLeft','');
    jsPrintSetup.setOption('footerStrRight','');
    jsPrintSetup.setOption('footerStrRight','');

    jsPrintSetup.setOption('edgeTop', 0);
    jsPrintSetup.setOption('edgeBottom', 0);
    jsPrintSetup.setOption('edgeLeft',0);
    jsPrintSetup.setOption('edgeRight',0);

    jsPrintSetup.setOption('unwriteableMarginTop', 0);
    jsPrintSetup.setOption('unwriteableMarginBottom', 0);
    jsPrintSetup.setOption('unwriteableMarginLeft', 0);
    jsPrintSetup.setOption('unwriteableMarginRight', 0);

    jsPrintSetup.setOption('marginTop',mTop);
    jsPrintSetup.setOption('marginBottom',mBottom);
    jsPrintSetup.setOption('marginLeft',mLeft);
    jsPrintSetup.setOption('marginRight',mRight);
    jsPrintSetup.setOption('orientation',orient);
    if (scalling) { jsPrintSetup.setOption('shrinkToFit',false);jsPrintSetup.setOption('scaling',scalling); }
    else jsPrintSetup.setOption('shrinkToFit',true);
    //send to print
    jsPrintSetup.clearSilentPrint();
    jsPrintSetup.setOption('printSilent',1);
    jsPrintSetup.printWindow(win);
//  win.close(); // can be replaced with setTimeOut(function () {win.close();}, 3000);
}  
koopee commented 8 years ago

I have a 80mm star receipt printer connected to Linux machine, which does not work properly with version 0.9.5.3.

With 0.9.2 version, jsPrint gets paper dimensions correctly from Firefox. GetPaperMeasure prints {"PD":null,"W":199.67,"H":71.97}, which is correct paper size.

JsPrint version 0.9.3 changes the paper size to A4, which results in a really small font. I can make the text larger using definePaperSize:

jsPrintSetup.definePaperSize(200, 200, "80mm_receipt", "80mm_receipt", "80 mm receipt", 78, 200, jsPrintSetup.kPaperSizeMillimeters); jsPrintSetup.setPaperSizeData(200);

However, I can not use this approach. I need the Firefox to handle paper size for the printer because some other sites use A4 printer and not receipt printer.

mitkola commented 8 years ago

@koopee Can you send an sample code that reproduce the problem.

koopee commented 8 years ago

For version 0.9.5.3, while running the code in Firefox scratchpad, I noticed, that page refresh resets the page size. (In my case to A4, which does not work properly)

If after the reset, I set the page size to 72mm x 200mm from the "print dialog -> page setup" manually, printing works fine until I refresh the page.

My outputs from the alert(jsPrintSetup.getPaperMeasure());

Here is the test code: Tested with Ubuntu 14.04.4 LTS, Firefox 46.0.1 `

  jsPrintSetup.setShowPrintProgress(0);
  jsPrintSetup.clearSilentPrint();
  jsPrintSetup.setOption('printSilent', 0); // Changed to 0 for testing

  //jsPrintSetup.setPrinter(printerName); // printerName is where the page will be printed 

  jsPrintSetup.setOption('orientation', jsPrintSetup.kPortraitOrientation);
  jsPrintSetup.setOption('shrinkToFit', '1');
  // Reduce margins
  jsPrintSetup.setOption('unwriteableMarginTop', 10);
  jsPrintSetup.setOption('unwriteableMarginLeft', 0);
  jsPrintSetup.setOption('unwriteableMarginBottom', 0);
  jsPrintSetup.setOption('unwriteableMarginRight', 0);

  jsPrintSetup.setOption('marginTop',0);
  jsPrintSetup.setOption('marginBottom',0);
  jsPrintSetup.setOption('marginLeft',0);
  jsPrintSetup.setOption('marginRight',0);

  // Empty headers & footers
  jsPrintSetup.setOption('headerStrLeft', '');
  jsPrintSetup.setOption('headerStrCenter', '');
  jsPrintSetup.setOption('headerStrRight', '');
  jsPrintSetup.setOption('footerStrLeft', '');
  jsPrintSetup.setOption('footerStrCenter', '');
  jsPrintSetup.setOption('footerStrRight', '');

  //jsPrintSetup.definePaperSize(200, 200, '80mm_receipt', '80mm_receipt', '80 mm receipt', 78, 200, jsPrintSetup.kPaperSizeMillimeters);
  //jsPrintSetup.setPaperSizeData(200);

  alert(jsPrintSetup.getPaperMeasure());
  jsPrintSetup.print();

`

mitkola commented 8 years ago

You have to uncomment lines jsPrintSetup.definePaperSize and jsPrintSetup.setPaperSizeData(200) before print. I have tested on Debian 8.4, FF 46.0.1, jsPrintSetup 0.9.5.3 and works fine. You must consider that getPaperMeasure try to match paper name from about:config (print.print_paper_name) (for windows print.paperdata) with internal list of papers. https://github.com/edabg/jsprintsetup/wiki#getpapersizelist After page refresh there are active saved settings in FF preferences (about:config print*) and when you call getPaperMeasure you must expect to get these.

koopee commented 8 years ago

Thanks for the reply! However, I can not uncomment the lines, because the paper size is A4 in some environments and 80mm receipt in others. With previous JsPrintSetup versions, It was very practical to use Firefox page setup to define the correct page size for each computer.

See my previous comment: https://github.com/edabg/jsprintsetup/issues/15#issuecomment-222142666