Category / Section
How to view exported PDF document in WinRT SfDataGrid?
1 min read
You can export the SfDataGrid into Pdf and the exported Pdf document can be viewed in application itself by using Syncfusion PdfViewerControl.
You can export the SfDataGrid into Pdf by using SfDataGrid.ExportToPdf extension method available in Syncfusion.UI.Xaml.Grid.Converter namespace. The exported document can be loaded into PdfLoadedDocument and you can navigate the current page to PdfViewerpage that contains the SfPdfViewerControl as in the following code example.
C#
private void Button_Click(object sender, RoutedEventArgs e) { var document = this.sfdatagrid.ExportToPdf(); MemoryStream stream = new MemoryStream(); document.Save(stream); PdfLoadedDocument ldoc = new PdfLoadedDocument(stream); this.Frame.Navigate(typeof(PdfViewerpage), ldoc); }
The following code example illustrates the creation of SfPdfViewerControl in PdfViewerpage.
XAML
<Page x:Class="App1. PdfViewerpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App1" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:syncfusion="using:Syncfusion.Windows.PdfViewer" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" x:Name="Grid1"> <syncfusion:SfPdfViewerControl x:Name="pdfviewer"/> </Grid> </Page>
You can load the PdfLoadedDocument to SfPdfViewerControl in OnNavigatedTo method of PdfViewerpage as in the following code example.
C#
protected override void OnNavigatedTo(NavigationEventArgs e) { PdfLoadedDocument ldoc = (PdfLoadedDocument) e.Parameter; pdfviewer.LoadDocument(ldoc); }
Sample Links: