Visual Studio 打印带有图像的文档VB.net

rryofs0p  于 2023-02-09  发布在  .NET
关注(0)|答案(1)|浏览(225)

我们从PrintDocument

保存pdf时,可以获得pdf格式的图像
这里我添加了一个图片框,按钮,打印文档,打印预览对话框
打印文件

代码:

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

但当我保存该文件并打开它不包含图片。

nwnhqdif

nwnhqdif1#

也许您可以将图像保存在本地,然后打印出来。

相关问题