How to export PDF from data of datagrid?

2019-05-26 21:26发布

How can I export the data from DataGrid into PDF? The quick solution.

<DataGrid Name="table" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsTextSearchEnabled="True" Background="White">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Timestamp" Binding="{Binding StartDate}" SortDirection="Descending" SortMemberPath="StartDate" IsReadOnly="True" />
        <DataGridTextColumn Header="Title" Binding="{Binding Title}" IsReadOnly="True" />
        <DataGridTextColumn Header="Description" Binding="{Binding Description}" IsReadOnly="True" />
        <DataGridTextColumn Header="Type" Binding="{Binding Tag}" IsReadOnly="True" />
    </DataGrid.Columns>
</DataGrid>

2条回答
ゆ 、 Hurt°
2楼-- · 2019-05-26 22:16

You can use iTextSharp to do it. You can add DataGrid visual in iTextSharp Document and use its PdfWriter to write it to the pdf file.

Below is the simple tutorial on it.

http://www.c-sharpcorner.com/uploadfile/f2e803/basic-pdf-creation-using-itextsharp-part-i/

查看更多
相关推荐>>
3楼-- · 2019-05-26 22:25

You can use iTextSharp (http://sourceforge.net/projects/itextsharp/) to generate datagrid to pdf.

(or) Look at http://wpfextendeddatagrid.codeplex.com/

查看更多
登录 后发表回答