async void ShareButton_Clicked(object sender, EventArgs e)
 {
     if (Forms9Patch.ToPdfService.IsAvailable)
     {
         if (await webView.ToPdfAsync("output.pdf") is ToFileResult pdfResult)
         {
             if (pdfResult.IsError)
             {
                 using (Toast.Create("PDF Failure", pdfResult.Result)) { }
             }
             else
             {
                 var collection = new Forms9Patch.MimeItemCollection();
                 collection.AddBytesFromFile("application/pdf", pdfResult.Result);
                 Forms9Patch.Sharing.Share(collection, shareButton);
             }
         }
     }
     else
     {
         using (Toast.Create(null, "PDF Export is not available on this device")) { }
     }
 }
        async void OnDestinationSelector_SegmentTapped(object sender, SegmentedControlEventArgs e)
        {
            if (_processing)
            {
                return;
            }
            _processing = true;

            if (e.Segment.Text.Contains("PNG") && await Forms9Patch.ToPngService.ToPngAsync(_htmlEditor.Text, "myHtmlPage") is ToFileResult pngResult)
            {
                if (pngResult.IsError)
                {
                    using (Forms9Patch.Toast.Create("PNG error", pngResult.Result)) { }
                }
                else
                {
                    var entry = new Forms9Patch.MimeItemCollection();
                    entry.AddBytesFromFile("image/png", pngResult.Result);

                    if (e.Segment.Text.Contains("SHARE"))
                    {
                        Forms9Patch.Sharing.Share(entry, _destinationSelector);
                    }
                    else
                    {
                        Forms9Patch.Clipboard.Entry = entry;
                    }
                }
            }
            else if (e.Segment.Text.Contains("PDF"))
            {
                if (Device.RuntimePlatform == Device.UWP)
                {
                    using (Forms9Patch.Toast.Create("PDF export not available in UWP", "However, you can print to PDFs!  So, try <b>Print</b> and then select <b>Microsoft Print to PDF</b> as your printer.")) { }
                }
                else if (await Forms9Patch.ToPdfService.ToPdfAsync(_htmlEditor.Text, "myHtmlPage") is ToFileResult pdfResult)
                {
                    if (pdfResult.IsError)
                    {
                        using (Forms9Patch.Toast.Create("PDF error", pdfResult.Result)) { }
                    }
                    else
                    {
                        var entry = new Forms9Patch.MimeItemCollection();
                        entry.AddBytesFromFile("application/pdf", pdfResult.Result);

                        if (e.Segment.Text.Contains("SHARE"))
                        {
                            Forms9Patch.Sharing.Share(entry, _destinationSelector);
                        }
                        else
                        {
                            Forms9Patch.Clipboard.Entry = entry;
                        }
                    }
                }
            }
            else if (e.Segment.Text.Contains("PRINT"))
            {
                Forms9Patch.PrintService.Print(_htmlEditor.Text, "myHtmlPage");
            }
            _processing = false;
        }
Beispiel #3
0
 /// <summary>
 /// Share the specified MimeItemCollection.  iPad: sharing popup points at target.
 /// </summary>
 /// <param name="collection">Collection.</param>
 /// <param name="target">Target.</param>
 public static void Share(MimeItemCollection collection, VisualElement target) => Service?.Share(collection, target);
Beispiel #4
0
 /// <summary>
 /// Share the specified MimeItemCollection.  iPad: sharing popup points at target.
 /// </summary>
 /// <param name="collection">Collection.</param>
 /// <param name="target">Target.</param>
 public static void Share(MimeItemCollection collection, Segment target) => Service?.Share(collection, target._button);