Skip to content
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

webContents.print() causes margin on printed page #15375

Closed
kadirilkimen opened this issue Oct 24, 2018 · 9 comments
Closed

webContents.print() causes margin on printed page #15375

kadirilkimen opened this issue Oct 24, 2018 · 9 comments

Comments

@kadirilkimen
Copy link

  • Output of node_modules/.bin/electron --version: 3.0.5
  • Operating System (Platform and Version): Windows 10
  • Output of node_modules/.bin/electron --version on last known working Electron version (if applicable): i dont know

Expected Behavior
I have an html page needs to print on electron. When i print using chrome browser it works fine.
page

Actual behavior
When i print on electron it adds some margin on the top and left of the page. I tried a lot of tricks on CSS but i think it is not about css or design of the page.

Here is a simple page that prints with same margins :

`

<title>print test for electron</title> <style> body{ margin:0; padding:0; }

@media print
{
body.A4{ width: 210mm;}
}

@page
{
size: A4;
margin: 0mm;
padding : 0mm;
}

.sheet
{
width:210mm;
height:297mm;
border:1px solid #000;
page-break-after: always;
}
</style>

test
test
test
`

To Reproduce
Create a single electron app
open the page above and call window.print() or BrowserWindow.webContents.print()
print on any printer.

Note : I am not an expert to prepare printing styles on css. But my pages prints on the chrome browser as expected.

@welcome
Copy link

welcome bot commented Oct 24, 2018

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@BeatriceThalo
Copy link

Try this in your global styles.css (rather than in any particular angular sub-component's css), particularly cm, when I tried in it didn't work.

@page {
    /* prevents electron's additional margins around sheet-content (the first printedPage of: the html already sized 8.5x22) */
    margin-top: 0cm;
    margin-left: 0cm;
    margin-right: 0cm;
    /* prevents electron from printing a blank page between each sheet (the first and second printedPages of the tall html) */
    margin-bottom: -.5cm;
}

@kadirilkimen
Copy link
Author

Hello. Thanks for the answer and sorry for the late response.
I tried this margin fix but it didnt work.
I tried to make margin settings all 0cm, 0mm and 0px. It didnt work. Electron still keep adding a default margin on the pages.Even when i made a test print page without any content than a simple text, it still adding a default margin regardless of any @page or css settings.

@sofianguy
Copy link
Contributor

Thank you for taking the time to report this issue and helping to make Electron better.

The version of Electron you reported this on has been superseded by newer releases.

If you're still experiencing this issue in Electron v4.2.x or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.

I'm setting the blocked/need-info label for the above reasons. This issue will be closed 7 days from now if there is no response.

Thanks in advance! Your help is appreciated.

@sofianguy sofianguy added the blocked/need-info ❌ Cannot proceed without more information label Aug 9, 2019
@wkoncki
Copy link

wkoncki commented Aug 16, 2019

@sofianguy
I tried new printing options in Electron 7.0.0-beta2 and run into this issue as well. I've set margins to 'none' and prints still had automatic margins added. It seems that this issue is still present.

Edit: Oh and just so you know, this behaviour is not the same when printing to PDF. It seems that those two functionalities work quite differently.

@sofianguy sofianguy added 7-0-x and removed blocked/need-info ❌ Cannot proceed without more information labels Aug 19, 2019
@sofianguy sofianguy added this to Unsorted Issues in 7.2.x Aug 19, 2019
@sofianguy sofianguy moved this from Unsorted Issues to Doesn't Block Stable in 7.2.x Aug 21, 2019
@sofianguy sofianguy added the 7-1-x label Nov 6, 2019
@itechoverdose
Copy link

this issue still persist in version 8.0.0 as well. i would say most of electron issues are in printing and i wish you would look at them sooner cause some issues have been around since version 0.3

System : Windows x64 Ultimate
Electron : 8.0.0

@akash-rajput
Copy link

Same here any fixes?

@El1tED
Copy link

El1tED commented Nov 30, 2020

@akash-rajput hi did you find a fix?

@electron-triage
Copy link

The Electron version reported on this issue is no longer supported. See our supported versions documentation.

If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know.

Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
3.0.x / 3.1.x
Unsorted Issues
7.2.x
Doesn't Block Stable
Development

No branches or pull requests

8 participants