I'm using SPIRE EXPORT PDF as I want to generate from a datagridview (VB.NET 2010) a pdf ... I'm doing it through a mysql database as I didn't find a way to do it directly !
so the code below saves the data written in the datagridview to the mysql bdd and then, it does an SQL to PDF with SPIRE export pdf
- Code: Select all
'PrintDocument1.Print()
Dim oleDbConnection1 = New MySqlConnection()
Dim Server As String = "localhost"
Dim Db As String = "PINF"
Dim User As String = "root"
Dim Pwd As String = ""
oleDbConnection1.ConnectionString = "Server=" & Server & ";" _
& "Uid=" & User & ";" _
& "Pwd=" & Pwd & ";" _
& " Database=" & Db & ";"
Dim oleDbCommand1 As New MySqlCommand
oleDbCommand1.Connection = oleDbConnection1
oleDbConnection1.Open()
For i = 0 To dgv.RowCount - 2
oleDbCommand1.CommandText = "insert into ATL values ('" & dgv(0, i).Value & "', '" & dgv(1, i).Value & "', '" & dgv(2, i).Value & "', '" & dgv(3, i).Value & "', '" & dgv(4, i).Value & "', '" & dgv(5, i).Value & "', '" & dgv(6, i).Value & "')"
oleDbCommand1.ExecuteScalar()
Next
Dim pdfExport1 As New Spire.DataExport.PDF.PDFExport()
pdfExport1.PDFOptions.PageOptions.Orientation = 0
pdfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
pdfExport1.DataFormats.CultureName = "fr-FR"
pdfExport1.DataFormats.Currency = "€"
pdfExport1.DataFormats.DateTime = "d-M-yyyy"
pdfExport1.DataFormats.Float = "g"
pdfExport1.DataFormats.[Integer] = "g"
pdfExport1.DataFormats.Time = "H:mm"
pdfExport1.PDFOptions.HeaderFont.AllowCustomFont = True
pdfExport1.PDFOptions.DataFont.AllowCustomFont = True
pdfExport1.PDFOptions.FooterFont.AllowCustomFont = True
pdfExport1.PDFOptions.TitleFont.AllowCustomFont = True
pdfExport1.AutoFitColWidth = False
pdfExport1.FileName = "sample1.pdf"
pdfExport1.PDFOptions.DataFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
pdfExport1.PDFOptions.FooterFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
pdfExport1.PDFOptions.HeaderFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
pdfExport1.PDFOptions.PageOptions.Format = Spire.DataExport.PDF.PageFormat.User
pdfExport1.PDFOptions.PageOptions.Height = 11.67
pdfExport1.PDFOptions.PageOptions.MarginBottom = 0.78
pdfExport1.PDFOptions.PageOptions.MarginLeft = 1.17
pdfExport1.PDFOptions.PageOptions.MarginRight = 0.57
pdfExport1.PDFOptions.PageOptions.MarginTop = 0.78
pdfExport1.PDFOptions.PageOptions.Width = 20
pdfExport1.PDFOptions.TitleFont.CustomFont = New System.Drawing.Font("Arial", 10.0F)
pdfExport1.PDFOptions.ColSpacing = 0
pdfExport1.PDFOptions.RowSpacing = 2
pdfExport1.PDFOptions.GridLineWidth = 2
oleDbCommand1.CommandText = "select * from ATL"
pdfExport1.Header.Text = "ATL"
'pdfExport1.PDFOptions.TitleFont.CustomFont = New System.Drawing.Font("Arial", 20.0F, FontStyle.Bold)
pdfExport1.SQLCommand = oleDbCommand1
pdfExport1.SaveToFile()
oleDbConnection1.Close()
But in the resulted PDF file .... the display is bad, I mean there are not all columns displayed ... and the columns are too spaced ! I don't know how to reduce the spacing of the columns .. if someone knows ..
here is an example of a resulted PDF with the code above :
there are normally 7 columns .... I couldn't display the 7 columns without generating a small table (and as you see, the columns' name are superimposed), so we won't see anything as it would be small (the police), maybe if there is a way to not display the titles of the columns in one line, but 2-3 for example, it'd take lower place !....
If someone has an idea...
thanks ! =)