Jump to content
Sign in to follow this  
Chamuanza

[Resolvido] Guardar Imagem de FORM em PDF

Recommended Posts

Chamuanza

Um bem aja a todos

Tenho este código que me guarda a imagem do Form em Jpeg, mas o que pretendo era guardar em PDF.

Agradeço uma ajuda ou sugestão

//
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim gfxscreen As Graphics
    Dim bmpscreen As Bitmap
    If (SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK) Then
	    Button3.Visible = False
	    bmpscreen = New Bitmap(Me.Size.Width, Me.Size.Height, PixelFormat.Format32bppArgb)
	    gfxscreen = Graphics.FromImage(bmpscreen)
	    gfxscreen.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
	    bmpscreen.Save(SaveFileDialog1.FileName, ImageFormat.Jpeg)
    Else
	    Exit Sub
    End If
   End Sub

Share this post


Link to post
Share on other sites
Chamuanza

Olá bioshock

Fui ao site que indicas e retirei o código abaixo, que penso seja o mais adequado para o que pretendo, mas que apresenta algumas correções a fazer.

Pergunto se terei que acrescentar alguma referencia ao projecto e se sim qual

//
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf

Module Program

 ' VB.NET version of 'Hello World'
 Sub Main()
   ' Create a new PDF document
   Dim document As PdfDocument = New PdfDocument
   document.Info.Title = "Created with PDFsharp"

   ' Create an empty page
   Dim page As PdfPage = document.AddPage

   ' Get an XGraphics object for drawing
   Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

   ' Draw crossing lines
   Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))
   gfx.DrawLine(pen, New XPoint(0, 0), New XPoint(page.Width.Point, page.Height.Point))
   gfx.DrawLine(pen, New XPoint(page.Width.Point, 0), New XPoint(0, page.Height.Point))

   ' Draw an ellipse
   gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5)

   ' Create a font
   Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)

   ' Draw the texto
   gfx.DrawString("Hello, World!", font, XBrushes.Black, _
   New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center)

   ' Save the document...
   Dim filename As String = "HelloWorld.pdf"
   document.Save(filename)

   ' ...and start a viewer.
   Process.Start(filename)

 End Sub

End Module

Share this post


Link to post
Share on other sites
bioshock
nelsonr

Tens de adicionar uma referência ao dll no teu projecto (PdfSharp.dll)

Edited by nelsonr

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.