To download Source Code Click here > Convert To PDF.rar 

This article will explain on how to create a pdf document using VB.Net 2005.
I used the itextSharp.dll to achieve this task.
iText# or iTextSharp is a port of the iText open Source Java Library for PDF Generation written entirely in C# for the .Net Platform.

  1. Download iTextSharp.dll. To download click here > Download iTextSharp.dll
  2. Create New Windows Form Project in VB.Net.
  3. Go to Solution Explorer Right Click on the Project and click on Add Reference.
  4. Browse to iTestSharp.dll and click Ok.










  1. Add TextBox to the Form and Set its MultiLine Properties to True.
  2. Add a Button to the Form and Set its Text Properties to "Save to PDF".
  3. Add a SaveFileDialog to the Form.
  4. Now Right Click the Form and Click On View Code.
  5. Now Import the Following References 
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Collections.Generic
Imports iTextSharp.text
Imports iTextSharp.text.pdf

      6.  Now Double Click on the Button and write the following code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            'Create Docu ment class obejct and set its size to letter and give space left, right, Top, Bottom Margin
            Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
            Try
                Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(SaveFileDialog1.FileName  & ".pdf", FileMode.Create))
                'Open Document to write
                doc.Open()
                'Write some content
                Dim paragraph As New Paragraph(TextBox1.Text)
                ' Now add the above created text using different class object to our pdf document
                doc.Add(paragraph)
            Catch dex As DocumentException
                'Handle document exception
            Catch ioex As IOException
                'Handle IO exception
            Catch ex As Exception
                'Handle Other Exception
            Finally
                'Close document
                doc.Close()
                MessageBox.Show("Pdf File Created Successfully", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Try
        End If
    End Sub

That's All  

To download Source Code Click here > Convert To PDF.rar  

Help From : http://www.dotnetspark.com/kb/654-simple-way-to-create-pdf-document-using.aspx 

0 comments:

Post a Comment