edabg / jsprintsetup

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

JsPrint margin and scaling issue #29

Closed surabhiv closed 7 years ago

surabhiv commented 7 years ago

Hello, I have used js print for printing customization.It works well for orientation but my code not working for margin.I have set all margins zero and also set browser's margin zero,still it takes default margins.Please give me any solution for it.Here is code for A5 landscape.

Printing
Print Example ...
This is example1
This is example2
This is example3
This is example4


mitkola commented 7 years ago

If you are using standard paper sizes (in jsPrintSetup), the recommended way is to use them. For example for iso A5 this is paper id 11.(https://github.com/edabg/jsprintsetup/wiki#enhanced-paper-data-handling) I have attached an example which print without any margins.

<html>
  <head>
    <title>Printing</title> 
<style> 
* {
    box-sizing:border-box;
} 
body {
    font-family:verdana,arial; 
    font-size:10pt; 
    background:white;
    margin: 0px; 
}
div {
    width:100%;border:3px solid black;
    padding:3px;
}
</style> <script type="text/javascript"> 
function print_ex() {

    jsPrintSetup.setGlobalOption('DEBUG', true);
    jsPrintSetup.setPrinter('PDFCreator');

    jsPrintSetup.setPaperSizeData(11); // iso_a5
    jsPrintSetup.setOption('orientation',jsPrintSetup.kLandscapeOrientation);

    // unwriteable margins
    jsPrintSetup.setOption('unwriteableMarginTop',0);
    jsPrintSetup.setOption('unwriteableMarginLeft',0);
    jsPrintSetup.setOption('unwriteableMarginBottom',0);
    jsPrintSetup.setOption('unwriteableMarginRight',0);
    // The edge measurements define the positioning of the headers and footers on the page. 
    // They're measured as an offset from the "unwriteable margin".
    jsPrintSetup.setOption('edgeTop',0);
    jsPrintSetup.setOption('edgeBottom',0);
    jsPrintSetup.setOption('edgeLeft',0);
    jsPrintSetup.setOption('edgeRight',0);

    // set top margins in millimeters
    jsPrintSetup.setOption('marginTop',0);
    jsPrintSetup.setOption('marginBottom',0);
    jsPrintSetup.setOption('marginLeft',0);
    jsPrintSetup.setOption('marginRight',0);

    // 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', '');

    // Suppress print dialog
    jsPrintSetup.clearSilentPrint();
    jsPrintSetup.setSilentPrint(true);/** Set silent printing */
    // Do Print
    jsPrintSetup.print();
    // Restore print dialog
    jsPrintSetup.setSilentPrint(false); /** Set silent printing back to false */
}
</script>
  </head>
  <body onClick="print_ex()" style="border: 1px solid black;">
Print Example ...<br />
This is example1<br />
This is example2<br />
This is example3<br />
This is example4<br />
  </body>
</html>
surabhiv commented 7 years ago

Hello, Thanks for answer. I have tried your code.But getting below error:- //Error Message Error: message:Component returned failure code: 0x80480002 (NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND) [nsIWebBrowserPrint.print] result:2152202242 name:NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND filename:jar:file:///C:/Users/Administrator/AppData/Roaming/Mozilla/Firefox/Profiles/c141afol.default/extensions/jsprintsetup@edabg.com.xpi!/components/jsPrintSetup.js lineNumber:1557 columnNumber:0 data:null stack:jsPrintSetup.prototype.print@jar:file:///C:/Users/Administrator/AppData/Roaming/Mozilla/Firefox/Profiles/c141afol.default/extensions/jsprintsetup@edabg.com.xpi!/components/jsPrintSetup.js:1557:4 print_ex@file:///C:/wamp/www/print_js/gitdemo.html:58:2 onclick@file:///C:/wamp/www/print_js/gitdemo.html:1:1

location:JS frame :: jar:file:///C:/Users/Administrator/AppData/Roaming/Mozilla/Firefox/Profiles/c141afol.default/extensions/jsprintsetup@edabg.com.xpi!/components/jsPrintSetup.js :: jsPrintSetup.prototype.print :: line 1557 //Error message after this error ,I get printer selection error so I change printer name in setPrinter().It works but I still get margin as previous.

mitkola commented 7 years ago

In the example I'm using printer with name PDFCreator. Comment the line with selecting printer.

jsPrintSetup.setPrinter('PDFCreator');
surabhiv commented 7 years ago

sorry ,Still not getting desire output...

mitkola commented 7 years ago

On which platform are you testing? Can you submit full source of your code html+js?

surabhiv commented 7 years ago

I have attached the print preview which i am getting by this code print_image

mitkola commented 7 years ago

Print preview doesn't get your parameters from jsPrintSetup. Try to print to some kind of PDF or PS printer. On which platform are you testing? Which is brand/model of your printer?

surabhiv commented 7 years ago

I am working on mozilla 50.0 (Windows operating system) and using printer HP Deskjet

mitkola commented 7 years ago

Can you manually setup FF to print as you desired? Try to print on PDF or PS printer for testing.

surabhiv commented 7 years ago

Can you please elaborate FF...??

mitkola commented 7 years ago

FireFox

surabhiv commented 7 years ago

No,I cannot setup manually because ,i want to do it by javascript that's why i have used this addon.

mitkola commented 7 years ago

I know that you want to print via javascript. My question was. If you do manual print whats happen? Are margins and orientation correct?

surabhiv commented 7 years ago

okk...I will check it.

surabhiv commented 7 years ago

Hello, Thanks,I got solution for this problem,actually my printer does not support this size,so i create a custom page for this printer and it works .still margin right issue remain the same for all paper sizes.

mitkola commented 7 years ago

If you was defined custom paper you must use jsPrintSetup.definePaperSize with correct settings for your paper. It is very important to use correct paperData value (for Windows) and paperName for Linux. To find correct value for paperData under Windows you can do manual print on this paper form and then check in about:config value of setting print.printer_your_printer.print_paper_data.

surabhiv commented 7 years ago

Yes,I have used jsPrintSetup.definePaperSize for custom page.

mitkola commented 7 years ago

What are parameters of your custom paper size? What is value of paper_data and how you determined?

surabhiv commented 7 years ago

Solved...Thank you.