Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Cannot display ListView data when creating PDF using PdfSharp.Xamarin.Forms

I am new to xamarin and I am using PdfSharp.Xamarin.Forms nuget to create a PDF in Xamarin forms for both Android and iOS. Problem is I cannot render ListView. They have mentioned about it, and need to write a renderer for it. But I have no idea how to create and bind it.

This is how I did it.

    <Grid x:Name="mainGrid">


            <StackLayout Padding="4" Orientation="Vertical">

                <!--<Image HeightRequest="80" Source="logojpeg.jpg" Margin="0,0,0,5"/>-->

                <Label FontSize="18" TextColor="Black" FontFamily="{StaticResource timesNewRomanBold}" HorizontalOptions="CenterAndExpand" Text="Monthly Motor Renew List of Jayasekara (900585) as at January, 2020"/>
                <Label FontSize="18" TextColor="Black" FontFamily="{StaticResource timesNewRomanBold}" HorizontalOptions="CenterAndExpand" Text="Report generated on 27 December, 2019" Margin="0,0,0,5"/>

                <ListView x:Name="renewListView"
                              pdf:PdfRendererAttributes.ListRendererDelegate="{StaticResource PDFSampleListRendererDelegate}"
                            <ViewCell IsEnabled="false">





Code Behind

public partial class MotorRenewalFinalPrint : ContentPage
    public MotorRenewalFinalPrint()

    public MotorRenewalFinalPrint (List<MotorRenewalPrintData> newdd)
        InitializeComponent ();
        Title = "Save as PDF";
        renewListView.ItemsSource = newdd;

    private void pdf_Clicked(object sender, EventArgs e)

        var pdf = PDFManager.GeneratePDFFromView(mainGrid);
        var fileManager = DependencyService.Get<IFileIO>();
        string filePath = Path.Combine(fileManager.GetMyDocumentsPath(), "formpdf.pdf");
        DependencyService.Get<IPdfSave>().Save(pdf, filePath);


PDFSampleListRendererDelegate renderer

public class PDFSampleListRendererDelegate : PdfListViewRendererDelegate
    public override void DrawCell(ListView listView, int section, int row, XGraphics page, XRect bounds, double scaleFactor)
        base.DrawCell(listView, section, row, page, bounds, scaleFactor);

    public override void DrawFooter(ListView listView, int section, XGraphics page, XRect bounds, double scaleFactor)
        base.DrawFooter(listView, section, page, bounds, scaleFactor);

    public override double GetFooterHeight(ListView listView, int section)
        return base.GetFooterHeight(listView, section);

Best Answer


  • ColeXColeX Member, Xamarin Team Xamurai

    We should draw the cell in PDFSampleListRendererDelegate , implement the methods in the class .

    Do not implemnt ItemTemplate in xaml

    <ListView pdf:ListRendererDelegate="{StaticResource YourRendererDelegate}" .../>


  • dushan135dushan135 Member ✭✭
    edited January 2020

    I am getting Xamarin.Forms.Xaml.XamlParseException: Position 149:35. StaticResource not found for key PDFSampleListRendererDelegate error . I have used PDFSampleListRendererDelegate as YourRendererDelegate

  • dushan135dushan135 Member ✭✭
    edited January 2020

    Error has went now. But how should I map my list data to the ItemSource using this renderer? I have created a sample project and updated to the github. If you can please modify it with binding data. It would be grateful. ListView has two labels

    link :

  • dushan135dushan135 Member ✭✭
  • dushan135dushan135 Member ✭✭
    Can you tell me how to bind/pass the list data to PDFSampleListRendererDelegate ??
Sign In or Register to comment.