How to convert Xamarin.Forms XAML page to PDF file?

Selvamz16Selvamz16 Member ✭✭
edited May 2018 in Xamarin.Forms

In Xamarin.Forms, I want to convert my xaml page UI (sometimes my page is scrollable when having more content) into the PDF. I have tried the PDFSharp open source. But it works only on UWP and having some issues in iOS and Android.

So is there any free open source plugin available to convert XAML UI into PDF in all three platforms? If open source not available, is there any other way or work around to achieve it?

Thanks in advance.

Answers

  • JitendraJitendra USMember ✭✭

    Having same problem

  • anji_8202anji_8202 Member ✭✭

    Having the Same Problem

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Selvamz16 said:

    So is there any free open source plugin available to convert XAML UI into PDF in all three platforms? If open source not available, is there any other way or work around to achieve it?

    Thanks in advance.

    I don't know about Open Source one. But Syncfusion Xamarin Control package has got it. It also has a Community Edition too. Check this out.

  • anji_8202anji_8202 Member ✭✭

    @ShantimohanElchuri said:

    @Selvamz16 said:

    So is there any free open source plugin available to convert XAML UI into PDF in all three platforms? If open source not available, is there any other way or work around to achieve it?

    Thanks in advance.

    I don't know about Open Source one. But Syncfusion Xamarin Control package has got it. It also has a Community Edition too. Check this out.

    Hi ShantimohanElchuri,

    Can we pass XAML LAYOUT(Like Stacklayout,Grid and ScrollView) to this plugin?

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @anji_8202 said:

    @ShantimohanElchuri said:

    @Selvamz16 said:

    So is there any free open source plugin available to convert XAML UI into PDF in all three platforms? If open source not available, is there any other way or work around to achieve it?

    Thanks in advance.

    I don't know about Open Source one. But Syncfusion Xamarin Control package has got it. It also has a Community Edition too. Check this out.

    Hi ShantimohanElchuri,

    Can we pass XAML LAYOUT(Like Stacklayout,Grid and ScrollView) to this plugin?

    I have no idea as I myself didn't use it. Ask Syncfusion support.

  • hypnocoolhypnocool Member ✭✭

    there is no tutorial how to start it... im in the asking stage at syncfusion

  • SardorSardor Member

    Having the Same Problem

  • batmacibatmaci DEMember ✭✭✭✭✭

    it is not possible. you can use syncfusion pdf tool but you must design pdf yourself using rows and columns etc. like html design. however there is a way to convert website to pdf. there is also another forum thread regarding this, please search.

  • NortahNortah Member

    I managed to do it on iOS using PdfKit. Here is an exemple of implementation

    async void OnButtonClicked(object sender, EventArgs e)
    {
    //scroll to the top of the page
    await ScrollView.ScrollToAsync(0, 0, false).ConfigureAwait(false);

            // Create a new PDF document
            PdfDocument document = new PdfDocument();
    
            //Captures the XAML page as image and returns the image in memory stream
            var image = UIScreen.MainScreen.Capture();
            // Create a page with the printscreen
            PdfPage page1 = new PdfPage(image);
            document.InsertPage(page1, 0);
    
            //scroll to the second page (you have to set the size of the page manually)
            await ScrollView.ScrollToAsync(0, 940, false).ConfigureAwait(true);
    
            //Captures the XAML page as image and returns the image in memory stream
            image = UIScreen.MainScreen.Capture();
            // Create a page with the printscreen
            PdfPage page2 = new PdfPage(image);
    
            document.InsertPage(page2, 1);
    
            //Write file in temp folder
            document.Write(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),        "doc.pdf"));
        }
    

    The downside of this code is that you have toset the bottom of the page yourself which can lack in accuracy if you have a lot of pages in your xaml scrollview.

Sign In or Register to comment.