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

iOS8 hangs at [renderer numberOfPages] #12

Open
cliffjoyce opened this issue Sep 9, 2014 · 7 comments
Open

iOS8 hangs at [renderer numberOfPages] #12

cliffjoyce opened this issue Sep 9, 2014 · 7 comments

Comments

@cliffjoyce
Copy link

On iOS 8, the _savePdf method often (but not always) hangs at [renderer numberOfPages]. The more complex the page, the more likely the hang.

@ChrisBeeson
Copy link

I'm having the same issue... have you found a fix?

@cliffjoyce
Copy link
Author

It turns out that there's a CSS property called "page-break-after". When the source HTML includes this property, then the renderer hangs when attempting to calculate the numberOfPages-- but only in iOS 8 (not iOS 7 or 6). We use this CSS property to create HTML page breaks.

From the _savePdf method, we've tried setting various values for self.webView.paginationMode and self.webView.paginationBreakingMode. But those changes did not prevent the hang.

Our current thinking that we need to modify our HTML to exclude the "page-break-after" CSS, and devise some other way to control our HTML page breaks.

@ChrisBeeson
Copy link

Personally I'm not using that CSS property, but it still hangs.

It seems to be a new issue with UIPrintPageRenderer
- (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect;

@melsam
Copy link

melsam commented Sep 17, 2014

Thanks @cliffjoyce for the suggestion. Confirming that removing page-break-after solved the issue for me too. In my app, I removed page-break-after from one element and added page-break-before to another element to achieve the same result. This does seem to be an Apple bug in iOS 8, but at least the workaround seems to work.

@cliffjoyce
Copy link
Author

Thanks back at you @melsam. Your suggestion to use page-break-before resolved our issue as well.

@bcriscuolo
Copy link

Thanks to this thread, you folks got me out of a big jam. :)

iOS 9 still has the issue, including in the simulator.

My fix (client-side) was to replace any instances of "page-break-after" with the newer "break-after" CSS property prior to loading my web view; fully compatible and now working correctly.

@esutton
Copy link

esutton commented Mar 23, 2017

Thank you all!

  • Same thing on iOS 10.2.1 using page-break-before
  • Seems to occur when my reports get larger than 3 or 4 pages, for example a 17 page PDF.

The fix for me was to use suggestion similar to @bcriscuolo and change page-break-before to the newer "break-before" CSS property

const QString CssStyleSheet =
        "<style type=\"text/css\">"
        "@media print {"
        ".pagebreak-before:first-child { display: block; page-break-before: avoid; }"
        ".pagebreak-before { display: block; page-break-before: always; }"
        "}"
        ".odd {"
        "background-color: #efefef;"
        "}"
        ".even {"
        "background-color: #ffffff;"
        "}"
        "table {"
        "width: 100%;"
        "}"
        "th, td {"   /* *** \todo Fix. CSS th, td{} is messing up footer table alignment **** */
        "text-align: left;"
        "}"
        "</style>";

Changed to:

"<style type=\"text/css\">"
"@media print {"
".pagebreak-before:first-child { display: block; break-before: avoid; }"
".pagebreak-before { display: block; break-before: always; }"
"}"
".odd {"
"background-color: #efefef;"
"}"
".even {"
"background-color: #ffffff;"
"}"
"table {"
"width: 100%;"
"}"
"th, td {"   /* *** \todo Fix. CSS th, td{} is messing up footer table alignment **** */
"text-align: left;"
"}"
"</style>";

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

No branches or pull requests

5 participants