VB.NET - picture box (rectangle area ) to convert as pdf file vb.net 2008/2010

Asked By Manjunath D B on 15-May-12 11:18 AM

picture box (rectangle area ) to convert as pdf file

kalpana aparnathi replied to Manjunath D B on 15-May-12 03:14 PM
hi,

Try below code:


If openFileDialog2.ShowDialog() = DialogResult.OK Then
          If openFileDialog2.FileName.EndsWith(".pdf") = True Or openFileDialog2.FileName.EndsWith(".PDF") = True Or openFileDialog2.FileName.EndsWith(".Pdf") = True Then
            PictureBox2.Hide()
            PDFPictureBox2.LoadFile(openFileDialog2.FileName)
            Panel2.AutoScrollMinSize = PDFPictureBox.Size()
            PDFPictureBox.Show()
          Else
            PDFPictureBox.Hide()
            PictureBox2.ImageLocation = openFileDialog2.FileName
            PictureBox2.Load()
            Panel2.AutoScrollMinSize = PictureBox2.Image.Size()
            PictureBox2.Show()
          End If
End If
 

Regards,


[)ia6l0 iii replied to Manjunath D B on 15-May-12 09:27 PM
If an image is assigned to the PictureBox's Image property or you drew the rectange yourself, then you could just use the Save method of the picturebox. 

See below:
photoID.Image.Save(@"pathToSaveImage",ImageFormat.Jpeg);

Hope this helps.

Jitendra Faye replied to Manjunath D B on 16-May-12 12:21 AM
Hi ,

After searching I have found one solution , hope this will help you.


Private Sub ConvertBitmapToPDF(ByVal bm As Bitmap, ByVal FileName As String)

      Dim PDF As PDFCreatorPilotLib.PDFDocument4
      Dim ImageIndex As Integer
      Dim BitmapHandle As IntPtr

      PDF = StartDoc()
      BitmapHandle = bm.GetHbitmap()
      ImageIndex = PDF.AddImageFromHandle(BitmapHandle.ToInt32())
      PDF.DrawImage(ImageIndex, 100, 100, bm.Width, bm.Height, 0)

      SavePDFDoc(PDF, FileName)

    End Sub

for complete article follow this link-

http://www.colorpilot.com/pdfcreatorpilotmanual/How_to_convert_image_to_PDF_using_VB_NET.html

Jitendra Faye replied to Manjunath D B on 16-May-12 12:23 AM
Continue to previous post

For this first you need to add reference of PDFCreatorType dll.

follow this link-=

http://www.colorpilot.com/pdfcreatorpilotmanual/How_to_create_a_new_PDF_document_4.html
Goniey N (Mr. G) replied to Manjunath D B on 23-May-12 11:52 PM
You can do this & code is also so simple...


use below code :


Private Sub btnPrintPicture_Click(ByVal sender As Object, ByVal e As EventArgs)

      Dim myPrintDocument1 As System.Drawing.Printing.PrintDocument = newSystem.Drawing.Printing.PrintDocument()

      Dim myPrinDialog1 As New PrintDialog()

      AddHandler myPrintDocument1.PrintPage, newSystem.Drawing.Printing.PrintPageEventHandler(myPrintDocument2_PrintPage)

      myPrinDialog1.Document = myPrintDocument1

      If myPrinDialog1.ShowDialog() = DialogResult.OK Then

        myPrintDocument1.Print()

      End If

End Sub


Using This function it will only print of the Picturebox, as you want...

Private Sub myPrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs)

      Dim myBitmap2 As New Bitmap(Me.Width, Me.Height)

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

      e.Graphics.DrawImage(myBitmap2, 0, 0)

      myBitmap2.Dispose()

End Sub

you can print this as PDF...


Hope this will help to you...