שתף באמצעות


How print a report from a datagridview of a form in PDF format

Question

Monday, August 22, 2016 6:39 PM

How can I print a report from a datagridview of a form in PDF format?

All replies (4)

Tuesday, August 23, 2016 2:59 AM ✅Answered

Hi Eduardo,

You could first bind the data to datagridview. Then add the ‘DGVPrinter’ reference to your project, download from this link: http://www.codeproject.com/Articles/18042/Another-DataGridView-Printer

I create a simple demo about print a datagridview. Using button click event to print datagridview as report. The code snippet as following:

Imports DGVPrinterHelper
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Printer = New DGVPrinter
        Printer.Title = "DataGridView Report"
        Printer.SubTitle = "An Easy to Use DataGridView Printing Object"
        Printer.SubTitleFormatFlags = StringFormatFlags.LineLimit Or StringFormatFlags.NoClip
        Printer.PageNumbers = True
        Printer.PageNumberInHeader = False
        Printer.PorportionalColumns = True
        Printer.HeaderCellAlignment = StringAlignment.Near
        Printer.Footer = "Your Company Name Here"
        Printer.FooterSpacing = 15
        Printer.PrintDataGridView(Me.DataGridView1)
    End Sub
End Class

Best Regards,

Neda Zhang

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Tuesday, August 23, 2016 6:20 PM ✅Answered

You can use the iTextSharp library:

http://www.aspsnippets.com/Articles/Export-Windows-Forms-DataGridView-to-PDF-using-iTextSharp-C-and-VBNet.aspx

Paul ~~~~ Microsoft MVP (Visual Basic)


Wednesday, August 31, 2016 1:20 PM ✅Answered

Does this code generate a PDF as the OP requested?

Paul ~~~~ Microsoft MVP (Visual Basic)


Monday, September 5, 2016 2:22 PM

The next error appears: "The DGVPrinter type is not defined"

How can I solve this error?

Thanks in advance.