PrintDocument with Image VB.net

305 Views Asked by At

Is Possible to get Image in pdf where we save pdf from PrintDocument enter image description here

Here i added an picturebox , button, printdocument, printpreviewdialog

In printDocument enter image description here

Code:

Public Class Form2

    Private Sub PrintDocument2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
        Dim XPos, YPos As Long
        XPos = 300
        YPos = 20
        Dim MyFont As New Font("Arial", 18)
        e.Graphics.DrawString("Stack Overflow is Best", MyFont, Brushes.Black, XPos + 30, YPos)
        YPos += 50
        YPos += 75
        MyFont = New Font("Arial", 12)
        e.Graphics.DrawImage(PictureBox2.Image, XPos - 200, YPos + 50, 300, 300)
        
    End Sub


    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PrintPreviewDialog2.ShowDialog()
    End Sub
End Class

But while i save that file and open it doesn't contain picture.

enter image description here

1

There are 1 best solutions below

0
Jiachen Li-MSFT On

Maybe you can save the image locally and then print it.