如何使用vb.net和第三方dll将Form的位图图像转换为pdf [英] How to convert bitmap image of Form to pdf using vb.net and 3rd party dll
本文介绍了如何使用vb.net和第三方dll将Form的位图图像转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Form图像位图(其所有控件都已填充)直接保存到单个PDF文件中,而不先保存为Jpeg或其他格式。到目前为止,我的理解是我需要PDFSharp,iTextSharp或其他一些第三方dll文件来执行此操作,但我没有找到任何不首先保存为Jpeg或其他格式的示例。我在找不可能吗?
I am trying to save a Form image bitmap(with all of its controls filled) directly to a single PDF file without saving to Jpeg or other format first. My understanding so far is that I will need PDFSharp, iTextSharp or some other 3rd party dll file(s) to do this but I am not finding any examples that do not save to Jpeg or other format first. Am I looking for the impossible?
推荐答案
不,你不是在寻找不可能的事。尝试这个,虽然这个是在C#
将Windows窗体转换为PDF [ ^ ]
您可以尝试另一个,这是在VB.NET中。
https://social.msdn.microsoft.com/Forums/vstudio/en-US/a043244e-d7f1-416b-bd7b-6c6d7986647b/how-to-export-a-vbnet-windows -form-into-a-pdf-format?forum = vbgeneral [ ^ ]
No you are not looking for the impossible. Try this one, though this one is in C#
Convert a Windows Form to PDF[^]
You can try another one, this is in VB.NET.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/a043244e-d7f1-416b-bd7b-6c6d7986647b/how-to-export-a-vbnet-windows-form-into-a-pdf-format?forum=vbgeneral[^]
Imports System.IO
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf
Imports System.Drawing.Imaging
Public Class Form1
Private memImage As Bitmap
Private Sub captureScreen()
Dim myGraph As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memImage = New Bitmap(s.Width, s.Height, myGraph)
Dim memGraphics As Graphics = Graphics.FromImage(memImage)
memGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
captureScreen()
Dim doc As New PdfDocument()
Dim oPage As New PdfPage()
oPage.TrimMargins.Left = 30
oPage.TrimMargins.Top = 50
doc.Pages.Add(oPage)
Dim xgr As XGraphics = XGraphics.FromPdfPage(oPage)
Dim img As XImage = XImage.FromGdiPlusImage(memImage)
xgr.DrawImage(img, 0, 0)
Dim savefiledialog1 As New SaveFileDialog
savefiledialog1.FileName = "Save as... "
savefiledialog1.Filter = ("PDF File|*.pdf")
If savefiledialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
doc.Save(savefiledialog1.FileName)
doc.Close()
End If
img.Dispose()
End Sub
End Class
这篇关于如何使用vb.net和第三方dll将Form的位图图像转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文