1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
Dim pdfTable As New PdfPTable(DataGridView1.ColumnCount)
pdfTable.DefaultCell.Padding = 1
pdfTable.WidthPercentage = 100
pdfTable.HorizontalAlignment = Element.ALIGN_MIDDLE
pdfTable.DefaultCell.BorderWidth = 1
Dim font12Boldblack As New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 9.0F, iTextSharp.text.Font.BOLD, BaseColor.BLACK)
Dim font9Normal As New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 8.0F, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)
Dim font9BoldBlack As New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 8.0F, iTextSharp.text.Font.BOLD, BaseColor.BLACK)
Dim ptable As New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 8.0F, iTextSharp.text.Font.BOLD, BaseColor.BLACK)
'Adding Header row
For Each column As DataGridViewColumn In DataGridView1.Columns
Dim cell As New PdfPCell(New Phrase(column.HeaderText, ptable))
cell.BackgroundColor = New iTextSharp.text.BaseColor(240, 240, 240)
pdfTable.AddCell(cell)
Next
i = -1
For Each row As DataGridViewRow In DataGridView1.Rows
i = i + 1
Next
'Affichage des Cellules colorées
Dim c As Color
For i = 1 To Me.DataGridView1.RowCount - 1
For j = 0 To DataGridView1.Columns.Count - 1
Dim cellText As String = DataGridView1.Rows(i - 1).Cells(j).Value.ToString
Dim cell As New PdfPCell(New Phrase(cellText, font9Normal))
'cell.FixedHeight = 25.0F
c = DataGridView1.Rows(i - 1).Cells(j).Style.BackColor
Dim aRGB As Integer = c.ToArgb
Dim RED, GREEN, BLUE As Integer
RED = Color.FromArgb(aRGB).R
GREEN = Color.FromArgb(aRGB).G
BLUE = Color.FromArgb(aRGB).B
Dim value As Integer = c.ToArgb()
Dim hex As String = value.ToString("X6")
If hex <> "000000" Then
cell.BackgroundColor = New BaseColor(RED, GREEN, BLUE)
End If
pdfTable.AddCell(cell)
Next
Next
'Exporting to PDF
Dim folderPath As String = My.Application.Info.DirectoryPath + "\export\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using stream As New FileStream(folderPath & "Export_Pdf.pdf", FileMode.Create)
Dim pdfDoc As New Document(PageSize.A4.Rotate, 10.0F, 10.0F, 10.0F, 0.0F)
PdfWriter.GetInstance(pdfDoc, stream)
pdfDoc.Open()
ProgressBar1.PerformStep()
pdfDoc.Add(New Phrase(New Chunk(titre, font12Boldblack)))
pdfDoc.Add(pdfTable)
Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance("images\image.jpg")
img.ScalePercent(50.0F)
img.ScaleToFit(250.0F, 250.0F)
pdfDoc.Add(img)
pdfDoc.Add(New Phrase(New Chunk("© Copyright 2017 - Didier POHU - EMPLOI Suivi® - ", font9BoldBlack)))
pdfDoc.Add(New Phrase(New Chunk("Site EMPLOI Suivi : http://contact72.free.fr//sites/EMPLOI_Suivi/", font9BoldBlack)))
pdfDoc.Close()
stream.Close()
Process.Start(folderPath & "Export_Pdf.pdf")
End Using
Menu_Base.Label89.Text = "! EXPORT RÉUSSI !" |
Partager