19-12-19, 12:11 AM
(آخر تعديل لهذه المشاركة : 19-12-19, 01:33 AM {2} بواسطة sofiane-phy.)
يعطيك الصحة أخي ، تتبعت الفيديو لكن لم ينجح معي نقل الكتابة من التكست بكس الى ملف الـ PDF
هذا نفس كود الفيديو ، فقط في الفيديو يستعمل تكست بوكس 2 مسار الملف المصدر و انا في مشروعي لا استعمل تكست بوكس 2 الملف انا اختار اين احفضه ، هل من الممكن تصحيح الكود بارك الله فيك أو من احد الاخوة جزاهم الله كل خير
هذا نفس كود الفيديو ، فقط في الفيديو يستعمل تكست بوكس 2 مسار الملف المصدر و انا في مشروعي لا استعمل تكست بوكس 2 الملف انا اختار اين احفضه ، هل من الممكن تصحيح الكود بارك الله فيك أو من احد الاخوة جزاهم الله كل خير
كود :
Imports System.Data.Odbc ' import namespaces ODBC class
Imports iTextSharp.text ' import namespaces .net pdf library
Imports iTextSharp.text.pdf
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
openconnection() ' open our connection
Dim da As OdbcDataAdapter ' declaration data adapter
Dim dt As DataTable ' declaration data table
da = New OdbcDataAdapter("SELECT idsiswa,nama,nis,tempatlahir,alamat FROM biodata", connection)
dt = New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt ' bind data table into datagridview
DataGridView1.Refresh()
connection.Close() ' close our connection
da.Dispose()
'configuration fo save file dialog
SaveFileDialog1.FileName = ""
SaveFileDialog1.Filter = "PDF (*.pdf)|*.pdf"
TextBox1.Text = "" ' for title
TextBox2.Text = "" ' for file locations
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SaveFileDialog1.FileName = ""
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
' declaration textbox2 to save file dialog name
TextBox2.Text = SaveFileDialog1.FileName
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' you must import itextsharp namespace into our form
' download links is available in the descriptions
Dim Paragraph As New Paragraph ' declaration for new paragraph
Dim PdfFile As New Document(PageSize.A4, 40, 40, 40, 20) ' set pdf page size
PdfFile.AddTitle(TextBox1.Text) ' set our pdf title
Dim Write As PdfWriter = PdfWriter.GetInstance(PdfFile, New FileStream(TextBox2.Text, FileMode.Create))
PdfFile.Open()
' declaration font type
Dim pTitle As New Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK)
Dim pTable As New Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)
' insert title into pdf file
Paragraph = New Paragraph(New Chunk(TextBox1.Text, pTitle))
Paragraph.Alignment = Element.ALIGN_CENTER
Paragraph.SpacingAfter = 5.0F
' set and add page with current settings
PdfFile.Add(Paragraph)
' create data into table
Dim PdfTable As New PdfPTable(DataGridView1.Columns.Count)
' setting width of table
PdfTable.TotalWidth = 500.0F
PdfTable.LockedWidth = True
Dim widths(0 To DataGridView1.Columns.Count - 1) As Single
For i As Integer = 0 To DataGridView1.Columns.Count - 1
widths(i) = 1.0F
Next
PdfTable.SetWidths(widths)
PdfTable.HorizontalAlignment = 0
PdfTable.SpacingBefore = 5.0F
' declaration pdf cells
Dim pdfcell As PdfPCell = New PdfPCell
' create pdf header
For i As Integer = 0 To DataGridView1.Columns.Count - 1
pdfcell = New PdfPCell(New Phrase(New Chunk(DataGridView1.Columns(i).HeaderText, pTable)))
' alignment header table
pdfcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT
' add cells into pdf table
PdfTable.AddCell(pdfcell)
Next
' add data into pdf table
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For j As Integer = 0 To DataGridView1.Columns.Count - 1
pdfcell = New PdfPCell(New Phrase(DataGridView1(j, i).Value.ToString(), pTable))
PdfTable.HorizontalAlignment = PdfPCell.ALIGN_LEFT
PdfTable.AddCell(pdfcell)
Next
Next
' add pdf table into pdf document
PdfFile.Add(PdfTable)
PdfFile.Close() ' close all sessions
' show message if hasben exported
MessageBox.Show("PDF format success exported !", "Informations", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Close()
End Sub------------------------
منكم أتعلم
------------------------
