Skip to content

iOS 16.4 printing - background graphics support #294

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rozekfr
Copy link

@rozekfr rozekfr commented May 26, 2023

iOS 16.4 add property to allow background graphics when printing the web page. Default value is false, so I need to do this change to allow background graphics.

There is a link to Apple change log.

rozekfr added 2 commits May 26, 2023 11:58
iOS 16.4 add property to allow background graphics when printing the web page. Default value is false, so I need to do this change to allow background graphics.
Only set shouldPrintBackgrounds by options.
@liamjones
Copy link
Contributor

Thank you for finding this! It was driving me mad and I'd not discovered the cause myself. 😄

Copy link
Contributor

@liamjones liamjones left a comment

Choose a reason for hiding this comment

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

Having applied this to a project locally I've got a couple of suggested fixes (it didn't work applied as-is).


if (@available(iOS 16.4, *)) {
if (options[@"backgroundGraphics"]) {
_webView.configuration.preferences.shouldPrintBackgrounds = [options[@"backgroundGraphics"] boolValue];
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the option should be converted via RCTConvert.

Suggested change
_webView.configuration.preferences.shouldPrintBackgrounds = [options[@"backgroundGraphics"] boolValue];
_webView.configuration.preferences.shouldPrintBackgrounds = [RCTConvert BOOL:options[@"backgroundGraphics"]];

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, [WKWebView configuration] should only be accessed from the main thread.

Suggested change
_webView.configuration.preferences.shouldPrintBackgrounds = [options[@"backgroundGraphics"] boolValue];
dispatch_sync(dispatch_get_main_queue(), ^{
_webView.configuration.preferences.shouldPrintBackgrounds = [RCTConvert BOOL:options[@"backgroundGraphics"]];
});

Choose a reason for hiding this comment

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

Thank you for saving my day 🥳

Copy link

stale bot commented Mar 13, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 13, 2024
@stale stale bot closed this Jan 21, 2025
@stale stale bot removed the stale label Jan 21, 2025
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.

6 participants