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

[Bug] await HTML to PDF "ToPdfAsync" doesn't return and lock the UI on iOS #105

Open
XamMattia83 opened this issue Mar 16, 2022 · 3 comments

Comments

@XamMattia83
Copy link

Description

On Real iOS devices, the await html.ToPdfAsync call doens't return 100% of the time and freeze the UI main thread
On Android it works.

Steps to Reproduce

  1. create an html string
  2. call the await.ToPdfAsync(htmlfile, filename, pagesize, margin) as in your demo code

Expected Behavior

the called Task must return

Actual Behavior

it doesn't return 100% of the time.

Basic Information

  • Version with issue: guess all
  • Last known good version: none
  • IDE:
  • Platform Target Frameworks:
    • iOS: 11
    • Android: 11
    • UWP:
  • Android Support Library Version:
  • Nuget Packages: Forms9Patch 2.4.9
  • Affected Devices: all real iOS devices

Screenshots

Reproduction Link - a link to a small demo project that reproduces this issue

                        try
                        {
                            if (Forms9Patch.ToPdfService.IsAvailable)
                            {
                                if (await htmlfile.ToPdfAsync(ReportFileName, PageSize.IsoA4) is ToFileResult pdfResult)
                                {
                                    if (pdfResult.IsError)
                                    {                                      
                                        await _userDialogs.AlertAsync(AppResources.StrReportGenerationError + pdfResult.Result);
                                    }
                                    else
                                    {   
                                        await Launcher.OpenAsync(new OpenFileRequest
                                        {
                                            Title = AppResources.OpenWithString,
                                            File = new ReadOnlyFile(pdfResult.Result)
                                        });
                                    }
                                }
                            }
                            else
                            {                             
                                await _userDialogs.AlertAsync(AppResources.StrPdfNonDisponibile);
                            }
                        }
                        catch (Exception err)
                        {                           
                            await _userDialogs.AlertAsync(AppResources.StrReportGenerationError + err);
                        }

Workaround

@smalgin
Copy link
Contributor

smalgin commented Dec 3, 2022

I have very similar issue with the Android - nothing happens. Investigating.

@smalgin
Copy link
Contributor

smalgin commented Dec 8, 2022

Okay, here's the fix that I made:

  1. forked PdfService for easier editing.
  2. enclosed the webview construction and initialization in the Device.InvokeOnMainThreadAsync() block.

That resolved the 'doing nothing' problem. Apparently, Webkit's WebView MUST be initialized on the main thread.

@smalgin
Copy link
Contributor

smalgin commented Dec 11, 2022

FYI - the same problem was on both Android and iOS, so you will have to make changes in the both of ToPDF() implementations.

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

2 participants