14-07-24, 02:33 PM
السلام عليكم ورحمة الله وبركاته
اول قم بجلب البيانات
ثانياً اضف هذه الدالة
ثالثاً في حدث الزر
اول قم بجلب البيانات
PHP كود :
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
ثانياً اضف هذه الدالة
PHP كود :
Private Sub ConvertImageToPDF(imagePath As String, pdfPath As String)
Using doc As New Document()
Try
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdfPath, FileMode.Create))
doc.Open()
Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imagePath)
Dim originalWidth As Single = img.Width
Dim originalHeight As Single = img.Height
If originalWidth > originalHeight Then
img.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height)
Else
img.ScaleToFit(doc.PageSize.Height, doc.PageSize.Width)
End If
doc.NewPage()
img.SetAbsolutePosition(0, doc.PageSize.Height - img.ScaledHeight)
doc.Add(img)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
doc.Close()
End Try
End Using
End Sub
ثالثاً في حدث الزر
PHP كود :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim openFileDialog As New OpenFileDialog()
openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.gif;*.bmp"
openFileDialog.Title = "Select an Image File"
If openFileDialog.ShowDialog() = DialogResult.OK Then
Dim imagePath As String = openFileDialog.FileName
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Filter = "PDF Files|*.pdf"
saveFileDialog.Title = "Save PDF File"
If saveFileDialog.ShowDialog() = DialogResult.OK Then
Dim pdfPath As String = saveFileDialog.FileName
ConvertImageToPDF(imagePath, pdfPath)
MessageBox.Show("Image converted to PDF successfully!")
End If
End If
End Sub

