如何将Picturebox插入现有的pdf或docx文件?

时间:2019-01-24 12:42:15

标签: vb.net-2010

如果我插入picturebox1,我的模板就清楚了。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Try
        Dim pdfDoc As New Document
        Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream("C:\Users\PC\Desktop\CERTIFICATION.PDF", FileMode.Open))
        pdfDoc.Open()
        dbpic()
        Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(PictureBox1.Image, System.Drawing.Imaging.ImageFormat.Jpeg)
        img.ScalePercent(50.0F)
        img.ScaleToFit(100.0F, 100.0F)
        pdfDoc.Add(img)
        pdfDoc.Close()
        AxAcroPDF1.src = ("C:\Users\PC\Desktop\CERTIFICATION.PDF")
    Catch ex As Exception
    End Try
End Sub
Public Sub dbpic()
    'Dim konek As New MySqlConnection("server = 192.168.1.1; user id = capstone; password = server; database = db_bisadms")
    Dim konek As New MySqlConnection("server = localhost; user id = root ; password =  ; database = db_bisadms")
    Dim command2 As New MySqlCommand("SELECT profile FROM images WHERE barcode = @iid", konek)
    command2.Parameters.Add("@iid", MySqlDbType.VarChar).Value = TextBox1.Text
    Dim adapter2 As New MySqlDataAdapter(command2)
    Dim table2 As New DataTable()
    Try
        konek.Open()
        adapter2.Fill(table2)
        Dim imgByte() As Byte

        If table2.Rows.Count = 1 Then
            imgByte = table2(0)(0)
            Dim ms As New MemoryStream(imgByte)
            PictureBox1.Image = FromStream(ms)
        End If
        konek.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

PictureBox1。图像发送到PDF或Word文档。

0 个答案:

没有答案