How do I take a screenshot of my project file, and then export/convert said file into a PDF, using vb.net?

Viewed 54

I am trying to take the contents of my project file and turning/export it as a PDF. For context, here is the layout of my project file:

My project file (tax calculator, essentially)

Don't mind the numbers, I was just testing that part of the code, my only issue is finding a way in taking that project file and turning it into a PDF. I tried breaking down this task into two buttons, the 2) Save File and 3) Create PDF buttons, though now I'm just getting more confused the more I try to do this.

Here is my code for the "2) Save File" button:

Private Sub Screenshot_Click(sender As Object, e As EventArgs) Handles Screenshot.Click
    Dim bmp As New Bitmap(Me.Width, Me.Height)

    Me.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Width, Me.Height))

    PictureBox1.Image = bmp

    bmp.Save(My.Computer.FileSystem.SpecialDirectories.Desktop & "\" & ".png", Imaging.ImageFormat.Png)
    SaveFileDialog1.ShowDialog()
    SaveFileDialog1.Title = "Save file"
    SaveFileDialog1.InitialDirectory = "E:\French"

    Dim location As String

    location = SaveFileDialog1.FileName
    bmp.Save(SaveFileDialog1.ShowDialog())
End Sub

The 3) Create PDF button doesn't currently have any special code, all I did was to try and create a bitmap and then taking that bitmap and turning it into a PDF:

Private Sub PDFbutton_Click(sender As Object, e As EventArgs) Handles PDFbutton.Click
    Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
    ' Create a graphics object from the bitmap  
    Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
    ' Take a screenshot of the entire Form1  
    gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
    ' Save the screenshot   
    bmpScreenshot.Save("D:\Form1.jpg", ImageFormat.Jpeg)
End Sub

Just started working on vb.net, so I'm still new at this. I'll gladly take any help and/or advice!

0 Answers
Related