Save file option is not available during print in iOS below 15 version

Paliwal, Vishal (Cognizant) 21 Reputation points
2022-03-10T07:25:12.307+00:00

We are trying to print pdf using xamarin native ios app. and print is not available and trying to save pdf using default save feature in ios.
In the latest ios 15 version this feature is working as expected. But in the below 15 version initially print option is disabled before selecting the printer. so we are not getting the option to save the pdf file since the print option is disabled in the lower version.

Please find the code snippet below used to Print PDF.

private void PrintPDF()
{
try
{

            UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;  

            printer.ShowsPageRange = true;  

            printer.PrintInfo = UIPrintInfo.PrintInfo;  
            printer.PrintInfo.OutputType = UIPrintInfoOutputType.General;  
            printer.PrintInfo.JobName = Constants.ConstantValues.JObName;  

            printer.PrintPageRenderer = new UIPrintPageRenderer()  
            {  
                HeaderHeight = 40,  
                FooterHeight = 40  
            };  
            printer.PrintPageRenderer.AddPrintFormatter(PDFWKWebView.ViewPrintFormatter, 0);  
              
            printer.PresentAsync(true);  
        }  
        catch (Exception e)  
        {  
            Console.WriteLine("Exception: " + e.Message);  
        }  
    }  

sample screenshot for print or save option available in ios 15 version.
181719-printoptionios15.png

Sample screenshot for print option is disabled for lower version.
181787-simulator-screen-shot-iphone-6s-plus-2022-03-08-at.png

Kindly help me resolved this issue.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,343 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 30,831 Reputation points Microsoft Vendor
    2022-03-11T09:03:22.18+00:00

    Hello @Paliwal, Vishal (Cognizant) ,

    From the codes you provided, I see that you want to print this PDFWKWebView, saving PDF is disabled because the preview of this page is blank in the lower version. If the preview is loaded, you could long press or zoom on this preview, then you will go to the detail page, and you could save this PDF file by clicking the share button. To make sure the preview can load, try to call this PrintPDF() method after all the data of webview is loaded (use WKNavigationDelegate.DidFinishNavigation(WKWebView, WKNavigation) Method ). Refer to the following code:

     public void LoadWebView()//load a webview to test  
            {  
               WKWebView PDFWKWebView = new WKWebView(new CoreGraphics.CGRect(0, 0, 300, 300), new WKWebViewConfiguration());  
                PDFWKWebView.NavigationDelegate = new WKWebViewDelegate();//key point, set NavigationDelegate   
                var url = new NSUrl("https://learn.microsoft.com");  
                var request = new NSUrlRequest(url);  
                PDFWKWebView.LoadRequest(request);  
            }  
    

    The WKWebViewDelegate class extending from WKNavigationDelegate

    public class WKWebViewDelegate : WKNavigationDelegate  
        {  
            public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)  
            {  
                PrintPDF(webView);  
            }  
            public void PrintPDF(WKWebView PDFWKWebView)  
            {  
              ......//your method  
            }  
        }  
    

    But the Print button will be disabled before selecting the printer.

    --------UPDATE--------

    After iOS 15, when you click print button, this Print Opentions view will pop up. Before iOS15, you need to long press the preview or two fingers to zoom in the preview(if you are using simulator, try to press the Option Key on the keyboard and drag the mouse). The preview image you provided in the lower version is blank(under "1 Copy" line). If this preview has been loaded, you could do this operation.

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.