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() doesn't work under Windows when 'deviceName' is provided #17260

Closed
gozzoo opened this issue Mar 7, 2019 · 9 comments
Closed

Comments

@gozzoo
Copy link

gozzoo commented Mar 7, 2019

  • Electron Version 4.0.7
  • Operating System Windows 10 32 bit
  • Last known working Electron version 3.1.3

Expected Behavior

webContents.print() should send print a job to the specified printer

Actual behavior

Nothing happens. Callback gets called much latter, for example on program exit.

printToPDF works though.

To Reproduce

let deviceName = 'HP LaserJet 1020'
let options = {deviceName, silent: true}
win.webContents.print(options, (err) => {
  if (!err)
    console.error('printing failed')
})

Related to #16792

@popod
Copy link
Contributor

popod commented Mar 7, 2019

@gozzoo the options param you sent to webContents.print() is false.

It should be: let options = { deviceName: deviceName, silent: true }.

@gozzoo
Copy link
Author

gozzoo commented Mar 7, 2019

@popod my example seems to be correct.

Just to make sure I run this in node:

let deviceName = 'HP LaserJet 1020'
let options = {deviceName, silent: true}
console.log(options)

and the output is this:

{ deviceName: 'HP LaserJet 1020', silent: true }

It's called 'Shorthand property names' and was introduced in ES2015.

Anyways I just checked my actual code and it is:

  win.webContents.print({deviceName: 'HP LaserJet 1020'}, (err) => ... )

@popod
Copy link
Contributor

popod commented Mar 7, 2019

@gozzoo yes, my bad ! your code seems to be correct :)

I'm having problems with webContents.print() too..

@shabeer-mdy
Copy link

I have the same problems too #17077

@Infinita740
Copy link

I have the same issue.

Can confirm printing is working as intended on Electron 3.1.6

(Win 10 64 bits)

@shabeer-mdy
Copy link

it's work fine but I change the default printer settings portrait to landscape then it prints as portrait, why this happening?

@azh117
Copy link

azh117 commented Mar 23, 2019

i am too facing same issue. Any update till when this will be resolved. i have to use old version of electron because of this.

@codebytere
Copy link
Member

codebytere commented Jun 24, 2019

This is working correctly when just deviceName is provided: the root cause of this issue you're experiencing is the silent print, which I'm investigating separately and which there exist other issues for.

@AkifB37
Copy link

AkifB37 commented Apr 17, 2021

works on this version
npm i electron@11.3.0

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

8 participants