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

feat: add MacOS print options #1259

Merged
merged 8 commits into from
May 14, 2024

Conversation

augustoccesar
Copy link
Contributor

Description

Currently, when printing on a MacOS, it defaults to a quite big margin, which does not reflect the side of it when printing on the web. The current code just creates a new NSPrintInfo from the default, which for some reason has a large margin.

This changes so that the default margin is 0 and add the option to change it when printing the webview on MacOs. This is not a field that can be changed by the user on the appkit modal, so it has to be defined before the modal is open.

Other options could be added on top of these ones, but for this initial commit/PR decided to go with adding the margins since it seems to be the one with bigger discrepancy compared to the web version.

Closes #713 (Not sure if should mark this as really close it since it really fixes only the margin part. The difference on the modal doesn't seem to be customisable as far as I understood from the docs).

References:

Screenshots:

Using the new print.rs in the examples folder.

Current default print

Default print with these changes

Currently, when printing on a MacOS, it defaults to a quite big margin, which does not reflect the side of
it when printing on the web. The current code just creates a new NSPrintInfo from the default, which for some
reason has a large margin.

This changes so that the default margin is 0 and add the option to change it when printing the webview on MacOs.
This is not a field that can be changed by the user on the appkit modal, so it has to be defined before the modal is open.

Other options could be added on top of these ones, but for this initial commit/PR decided to go with adding the margins
since it seems to be the one with bigger discrepancy compared to the web version.

References:
- https://developer.apple.com/documentation/appkit/nsprintinfo
@augustoccesar augustoccesar marked this pull request as ready for review May 12, 2024 17:46
@augustoccesar augustoccesar requested a review from a team as a code owner May 12, 2024 17:46
@pewsheen
Copy link
Contributor

Hi, can you add a changelog (https://github.com/tauri-apps/wry/tree/dev/.changes) and do a cargo fmt?

@augustoccesar
Copy link
Contributor Author

Hi, can you add a changelog (https://github.com/tauri-apps/wry/tree/dev/.changes) and do a cargo fmt?

Done! ✅
Put it as a minor, but let me know if that was classified incorrectly for the project.
It does fix what I believe to be a bug (the large margins when printing on MacOS), but also adds a new feature (the printing with extra options), so the minor felt more correct.

examples/print.rs Outdated Show resolved Hide resolved
.changes/macos_print_options.md Outdated Show resolved Hide resolved
src/wkwebview/mod.rs Outdated Show resolved Hide resolved
src/wkwebview/mod.rs Outdated Show resolved Hide resolved
.changes/macos_default_print_margins.md Outdated Show resolved Hide resolved
.changes/macos_print_margin_options.md Outdated Show resolved Hide resolved
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@amrbashir amrbashir merged commit 0f14e2a into tauri-apps:dev May 14, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MacOS: window.print() margins and dialog options differ
3 participants