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

<webview> printToPDF window content scales down in relation to page size if screen Display text/apps setting is greater than 100% #9118

Closed
midweststudios opened this issue Apr 5, 2017 · 5 comments

Comments

@midweststudios
Copy link

Using <webview>.printToPDF()

  • Electron version: 1.6.5 (upgraded in case latest version fixed issue)
  • Operating system: Windows 8 & Windows 10 (only when screen Display text/apps setting is scaled from 100%)

Expected behavior

PDF content fills entire height/width of print page size (i.e. ratio 1:1)

Actual behavior

Example for screen display scale set at 200% on a Windows Surface Pro 3:

  • var options = {marginsType: 1, pageSize: "Letter"}
    • I also tried height and width in microns for the pageSize

PDF exports at correct Letter size (8.5in x 11in) but the target content is scaled down 50% (4.25in x 5.5in) on the page.

@midweststudios
Copy link
Author

I think this can be resolved by making all of the key's assigned in const defaultPrintingSetting = {} available options within WebContents.prototype.printToPDF = function (options, callback) {...}. Then in my project file I can check for the screen's scaleFactor and/or it can be as simple as changing fitToPageEnabled: false to fitToPageEnabled: true. Won't know for sure until I run tests though.

Please reference: https://github.com/electron/electron/blob/master/lib/browser/api/web-contents.js

Note: I need to wrap up the project that's having this issue and would prefer just modifying the file from my local install, but I haven't been able to find the Electron .js source files. If anyone can point me in the right direction, I would greatly appreciated it!

@codebytere
Copy link
Member

We are no longer implementing bugfixes for versions of Electron <= 1.7.x, so i'm going to close this issue but if it is still persisting in more recent versions of Electron we can certainly reopen it!

@Alecyrus
Copy link
Contributor

Alecyrus commented Oct 5, 2019

I set page rule like this

@page { 
     size A4 portrait;

}
.content {
  background #fff
  box-shadow inset 0 0 1px 1px red
}

but every page of printed PDF by webContent.printToPDF always overflow. You can notice that the width of red edges is 1px, but the width of overflow part is smaller than 1px. Very strange.

Left corner
截屏2019-10-0514 02 40

Right corner

截屏2019-10-0514 07 15

And letter will be fine. A4A5 always overflow, which will cause another blank page being printed

When I change the page size from A4 (210mm 297mm) to 212mm 296.994mm, the overflow parts disappears. but the bottom of page still overflow because of the blank page .
截屏2019-10-0514 11 22

@Alecyrus
Copy link
Contributor

Alecyrus commented Oct 5, 2019

Is fitToPageEnabled available ?, I can not find it in official document.

@Alecyrus
Copy link
Contributor

Alecyrus commented Oct 5, 2019

#20436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants