# Export All ListView Pages to PDF

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC ListView</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.2.829 version</td>
 </tr>
</table>

## Description

How can I use the [Kendo UI Drawing](https://docs.telerik.com/kendo-ui/framework/drawing/overview) library to export all ListView pages to PDF?

## Solution

1. Add a button above the ListView that will be used for the PDF export.

   ```Razor HtmlHelper
       @(Html.Kendo().Button()
       .Name("pdfExportBtn")
       .Content("Export to PDF")
       .HtmlAttributes(new { type = "button" })
       .Events(ev => ev.Click("onClick")))
   ```

2. Within the button `click` event handler, get a reference to the ListView, store its page size into a global variable, and calculate the total records.

3. Call the [`pageSize()`](https://docs.telerik.com/kendo-ui/api/data/datasource/methods/pagesize) method of the DataSource to update the current page size with all available records to export them into the PDF file. Otherwise, the exported file will contain only the current page records.

4. Subscribe only once to the `DataBound` event of the ListView to ensure that all records are loaded.

5. Use the Kendo UI Drawing API to export the ListView content.

6. Change back the page size of the ListView.

```
    <script>
        function onClick() {
            var listView = $("#listView").data("kendoListView"); // Get a reference to the ListView.
            var currentPageSize = listView.dataSource.pageSize(); // Get the page size of the DataSource.
            var total = currentPageSize * listView.dataSource.totalPages(); // Calculate the total ListView records.

            listView.dataSource.pageSize(total); // Update the page size to display all records in a single page.
            listView.one("dataBound", function(){ // Subscribe once to the "dataBound" event of the ListView.
                kendo.drawing.drawDOM($(".listview-container"), { // Initialize the PDF export.
                    paperSize: "A4",
                    multiPage: true,
                    margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" }
                })
                .then(function (group) {
                    return kendo.drawing.exportPDF(group);
                })
                .done(function (data) {
                    kendo.saveAs({
                        dataURI: data,
                        fileName: "TestPrint.pdf"
                    });
                });
            });
            listView.dataSource.pageSize(currentPageSize); // Change back the page size.
        }
    </script>
```

For a runnable example based on the code above, refer to the [REPL example on exporting all ListView pages to PDF](https://netcorerepl.telerik.com/woORnlvw17pZ1uXr21).

## More ASP.NET MVC ListView Resources

* [ASP.NET MVC ListView Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/listview/overview)

* [ASP.NET MVC ListView Demos](https://demos.telerik.com/aspnet-mvc/listview/index)

* [ASP.NET MVC ListView Product Page](https://www.telerik.com/aspnet-mvc/listview)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the ListView for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/listview)

* [Server-Side API Reference of the ListView for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/listview)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
