Closed surabhiv closed 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>
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.
In the example I'm using printer with name PDFCreator
.
Comment the line with selecting printer.
jsPrintSetup.setPrinter('PDFCreator');
sorry ,Still not getting desire output...
On which platform are you testing? Can you submit full source of your code html+js?
I have attached the print preview which i am getting by this code
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?
I am working on mozilla 50.0 (Windows operating system) and using printer HP Deskjet
Can you manually setup FF to print as you desired? Try to print on PDF or PS printer for testing.
Can you please elaborate FF...??
FireFox
No,I cannot setup manually because ,i want to do it by javascript that's why i have used this addon.
I know that you want to print via javascript. My question was. If you do manual print whats happen? Are margins and orientation correct?
okk...I will check it.
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.
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
.
Yes,I have used jsPrintSetup.definePaperSize for custom page.
What are parameters of your custom paper size?
What is value of paper_data
and how you determined?
Solved...Thank you.
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.
This is example1
This is example2
This is example3
This is example4