New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Silent print was incorrect paper layout with webContents.print, but layout was correct when I use print dailog #39179
Comments
Everything work fine with "electron": "^24.6.4" for layout paper printing but I want to upgrade with new version and now I stuck on that problem. Thanks for help |
@codebytere Is this broken by the fix #39095? |
Any update with this issue? It also prevents us from upgrading to v25 and we haven't figured out a way to work around it. |
If it helps, you can use this gist to easily reproduce the issue: https://gist.github.com/053de2471f74277e60fb908aaa3685ff. Just click Print, save the PDF to any location, and then view it and see how tiny the printed contents are. |
@tyhour i have the same issue with electron@24.6.4 in silent mode, did you know how to solve it? |
Setting the dpi:{ horizontal: 600, vertical: 600 } on the printOptions can workaround the issue. |
Ran into this as well when trying to upgrade to 25.x (and 26.x). I was able to adjust the output size with the mentioned dpi-setting, but layout still differs from 24.x or non-silent printing. Had to downgrade back to 24.x because of this. E.g. 24.8.3 still works fine with silent printing. |
It seems this error still exists until the latest version The print function with option Has anyone solved this problem other than the trick above?
|
Is there any update on this? I'm using Zebra Printer ZD 230 with 4inch X 6inch roll. How to calculate the dpi? With silent: true in print option, is causing prints to be very tiny. I'm on electron 26.2.1 |
My current workaround for windows is to utilize PrinterResolution class get the printer resolution and pass the dpi to the printer to print. I've noticed some printer drivers(Canon generic printer driver) could return dpi values <=0. You'd need to filter them out and only pass the positive one to webContent.print. Otherwise, you could encounter this issue. |
I have exactly the same issue, and the 600 dpi workaround not working for me. |
But then you need to switch to C# Code or? The webContents.gerPrintersAsync() function didn't have the necessary DPI information right? Have the same problem with 27.1.0 |
Yes, I switched to C# to get the printer resolution and sent back to Electron's webContents.print() function. |
I have the same issue also on Electron 28.x. A thing I was able to discover is that, on Windows, pageSize is interpreted in the wrong way. To be able to print at full page I had to multiply by 10 the width and heights in microns, by means of the By means of that, the content is still printed small, but moves to the top-left corner and the print is able to span to the full page. To get to a normal printing size I can set I also verified that printing the page from Chrome or Chromium doesn't present the same issue, but I struggle to find where the problem is in the Electron code base. It seems like, by doing a FYI: On macOS everything is fine |
Having the same issue, I checked different versions today and can confirm the previous commenters. Would be great to have this fixed, since 24.x is already end of life, but this forces me to stay on that version. |
Thank you @Wexoo, I downgraded to 24.8.8 and it works perfectly |
We recently upgraded to the latest version and facing the font size issue while printing out. It's very tiny. We tried changing the DPI, but the printer is not printing at all. while removing it's working with a tiny font size. Need help/some work around to fix this issue. |
@codebytere Do we have a timeline or a specific Electron version targeted for fixing this issue? |
I have tried SEVERAL versions and this is still very much an issue. I mean my current fix attempt on printing an image is: ipcMain.handle("print-image", async (_, imagePath) => {
let imageWin = new BrowserWindow({
show: false,
webPreferences: {
images: true
}
});
imageWin.loadFile(imagePath);
return new Promise<void>((resolve, reject) => {
imageWin.webContents.on("did-finish-load", () => {
const options: Electron.WebContentsPrintOptions = {
silent: true,
landscape: true,
pageSize: "A6",
margins: {
marginType: "none" as const,
},
pagesPerSheet: 1,
dpi: {
horizontal: 600,
vertical: 600,
},
collate: false,
copies: 1,
};
imageWin.webContents.print(options, (success, failureReason) => {
if (success) {
resolve();
} else {
console.error(failureReason);
reject(new Error(failureReason));
}
imageWin.close();
});
});
});
}); The thing is... I can somewhat get it working. But for some magical reason, everything is stuck at the A4 scale, regardless of what page size I attempt to use or however I try enforce my settings, this one of many and I mean many attempts. I'm just over it now. |
@codebytere any news on this? |
I have the same issue, added |
This issue is actually not fixed. The pdf is generated fine but the prints are not triggered with proper layout in silent mode. #41928 explains it. |
Yes, it's not fixed yet, there is still the same issue in 31.0.0-alpha.2 |
For now, I have resorted back to https://www.npmjs.com/package/pdf-to-printer. While its not perfect, it helps me with most of the cases. I faced an issue with orientation, and only for Windows, I had to provide an additional orientation setting in my app, which overcame this issue. I think this ticket needs to be reopened till the printing issue is resolved. |
Preflight Checklist
Electron Version
25.3.1
What operating system are you using?
Windows
Operating System Version
Window 10 Pro Version 10.0.19045 Build 19045
What arch are you using?
x64
Last Known Working Electron version
25.3.1
Expected Behavior
This preview image I was use with dialog print. It shows exactly width and height that response from my URL. But I want to use with silent print.
Here is my code
Actual Behavior
This preview image I was use with silent print. It shows too small that response from my URL.
Here is my code
Testcase Gist URL
https://gist.github.com/053de2471f74277e60fb908aaa3685ff
Additional Information
No response
The text was updated successfully, but these errors were encountered: