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

[print][ios] fix width/ height not working on HTML print #20046

Merged

Conversation

keith-kurak
Copy link
Contributor

@keith-kurak keith-kurak commented Nov 14, 2022

Why

Fixes #16739, so now printing rendered HTML will change the page size when a custom width/ height is specified.

How

Setting width/ height stopped working after printing was changed from a snapshot-based method to HTML renderer based method, in order to properly support margins and page breaks. This stack overflow comment hinted that using UIGraphicsBeginPDFPageWithInfo with the paper size CGRect would do the trick, and, lo-and-behold, it seems to work!

Also noticed that margin wasn't reflected when useMarkupFormatter was set to true when calling printToFileAsync, and margin and page size weren't reflected when using the same option with printAsync, so fixed those with a similar change.

Test Plan

Tweaked the HTML from the docs' printing snack to simulate something akin to the label in the issue. Tried printAsync with no additional parameters, the same custom width/ height as in the issue, with custom margins, and with both custom dimensions and margins. Seems to look correct in all cases. Also tried printToFileAsync, and that worked, as well. Finally, to test the useMarkupFormatter = true fixes, tested both print functions with that on and off, and also tried omitting the html parameter to simulate an error.

Custom dimensions:

Custom margins:

Custom dimensions and margins

The test "label" in case anyone needs it:

<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
  </head>
  <body style="text-align: center;">
    <div style="border-width=2px; border-color=black; border-style: solid; width:190px; height:80px">
      <h3 style="font-size: 12px; font-family: Helvetica Neue; font-weight: normal;">
        Hello Expo!
      </h3>
      <img
        src="https://d30j33t1r58ioz.cloudfront.net/static/guides/sdk.png"
        style="width: 50px;" />
    </div>
  </body>
</html>

Checklist

@linear
Copy link

linear bot commented Nov 14, 2022

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Nov 14, 2022
@keith-kurak keith-kurak marked this pull request as ready for review November 15, 2022 21:05
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Nov 15, 2022
packages/expo-print/ios/EXPrint/EXPrint.m Outdated Show resolved Hide resolved
keith-kurak and others added 3 commits November 16, 2022 09:13
Co-authored-by: Kim Brandwijk <kim.brandwijk@gmail.com>
Co-authored-by: Łukasz Kosmaty <lukasz.kosmaty@swmansion.com>
@keith-kurak keith-kurak merged commit d0da0a3 into main Nov 18, 2022
@keith-kurak keith-kurak deleted the keith/eng-6915-expo-print-not-setting-width-height-on branch November 18, 2022 16:20
@borkanee
Copy link

When will this fix be released? Can we use it somehow in SDK 47?

@hotaryuzaki
Copy link

hotaryuzaki commented Jun 6, 2023

i already use 2.2.1 but why am i still cannot define custom width and height??
we tried in android, is it only works in iOS??????

await Print.printAsync({ html: response.data, height: 595, width: 842 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expo 44 - Expo Print - HTML Page Height/Width no longer recognized.
6 participants