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

fix: silent print settings #31489

Merged
merged 2 commits into from Oct 25, 2021
Merged

fix: silent print settings #31489

merged 2 commits into from Oct 25, 2021

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Oct 20, 2021

Description of Change

Closes #30889.
Closes #30340.
Closes #29334.
Closes #29286.

Fixes an issue introduced 46f3491 resultant of CL:2409467 which resulted in custom print settings not being properly propagated.

Checklist

Release Notes

Notes: Fixed an issue which caused print settings to not work properly when printing silently.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/13-x-y labels Oct 20, 2021
@codebytere codebytere requested a review from a team as a code owner October 20, 2021 07:49
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Oct 20, 2021
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Oct 21, 2021
@jkleinsc jkleinsc merged commit 2a4b262 into main Oct 25, 2021
@jkleinsc jkleinsc deleted the fix-silent-print branch October 25, 2021 15:52
@release-clerk
Copy link

release-clerk bot commented Oct 25, 2021

Release Notes Persisted

Fixed an issue which caused print settings to not work properly when printing silently.

@trop
Copy link
Contributor

trop bot commented Oct 25, 2021

I was unable to backport this PR to "13-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Oct 25, 2021

I was unable to backport this PR to "14-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Oct 25, 2021

I was unable to backport this PR to "16-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/14-x-y label Oct 25, 2021
@trop
Copy link
Contributor

trop bot commented Oct 25, 2021

I was unable to backport this PR to "15-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Oct 28, 2021

@codebytere has manually backported this PR to "13-x-y", please check out #31618

@latchuk
Copy link

latchuk commented Oct 28, 2021

@latchuk I need to do manual backports for this PR to release lines - i'll do that today if i can!

Thanks @codebytere. I'm waiting for this fix a long time. Than you so much!

@cxrxiu
Copy link

cxrxiu commented Oct 29, 2021

What version have this fix?

i have the same question

t57ser pushed a commit to t57ser/electron that referenced this pull request Oct 29, 2021
* fix: silent print settings

* chore: update patches

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
t57ser pushed a commit to t57ser/electron that referenced this pull request Oct 29, 2021
* fix: silent print settings

* chore: update patches

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
t57ser pushed a commit to t57ser/electron that referenced this pull request Oct 29, 2021
* fix: silent print settings

* chore: update patches

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
t57ser pushed a commit to t57ser/electron that referenced this pull request Oct 29, 2021
* fix: silent print settings

* chore: update patches

Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
@latchuk
Copy link

latchuk commented Oct 29, 2021

What version have this fix?

i have the same question

I think the new release with the fix come soon.

@latchuk
Copy link

latchuk commented Nov 1, 2021

Any ideia about the release date with this fix?

@baconbrad
Copy link
Contributor

The merged labels indicate they are now backported to 13.x, 14.x, and 15.x. So the next release for these versions will contain the fix. I do not know the official date but it could be likely in the next couple of days. In the meantime those branches can be built from source if you need it faster than the official release.

@baconbrad
Copy link
Contributor

baconbrad commented Nov 9, 2021

This update is now in official releases for 14.2.1 and 15.3.1. I have tested and verified it is working as expected in both.

Thanks, Electron Team!

@zhangxr2
Copy link

I test in version 15.3.1 when print, only footer is customized。header does not show my customized string。
below is my code。
image

@zhangxr2
Copy link

in my code,where is wrong?
why my ‘header‘ string does not show in printed paper?

@latchuk
Copy link

latchuk commented Nov 12, 2021

in my code,where is wrong? why my ‘header‘ string does not show in printed paper?

I'm printing using loadURL and it's ok.

function print(printerName, content, widthCm, heightCm) {
const printWindow = new BrowserWindow({ show: false });

const html = <!DOCTYPE html> <html> <head> <title>Zebra label</title> </head> <body> <style type="text/css" media="print"> @page{size: ${widthCm * 10}mm ${heightCm * 10}mm landscape;margin: 0; } </style> ${content} </body> </html>;

const printers = printWindow.webContents.getPrinters();
const printer = printers.find(x => x.name.includes(printerName));

if (!printer) {
throw new Error(The printer '${printerName}' was not found.);
}

printWindow.webContents.on('did-finish-load', () => {
printWindow.webContents.print(
{
silent: true,
margins: { marginType: 'none' },
scaleFactor: 100,
pageSize: {
height: heightCm * 1000,
width: widthCm * 1000,
},
deviceName: printer.name,
},
(success, failureReason) => {
if (printWindow.closable) {
printWindow.close();
}

    if (failureReason || !success) {
      // all its ok
    } else {
      // has some error
    }
  }
);

});

printWindow.webContents.on(
'did-fail-load',
(event, errorCode, errorDescription) => {
if (printWindow.closable) {
printWindow.close();
}
// has some error
}
);

printWindow.loadURL(data:text/html;charset=utf-8,${html});
}

@m4heshd
Copy link

m4heshd commented Nov 14, 2021

@latchuk A little tip for the future. You should consider using fenced code blocks when writing code snippets inside markdown content.

```js
// WRITE YOUR CODE IN HERE
```

Else it looks like a mess and hardly readable. Enclosing code inside a fenced code block formats your code automatically for better readability. And defining the language provides you with bonus features like syntax highlighting.

@zhangxr2
Copy link

I know why.
'<title>Zebra label</title>' has higher priority than
image

so, if I want to show custom print header ,I need delete <title>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
10 participants