PDF SDK by Mozon Soft that will make your application capable of generating PDF files in 15 minutes

PDF Toolkit/PDF SDK

Generate PDF Reports from your application in 15 minutes

Mozon Soft Home

Monzon Soft provides a PDF SDK that will make your application capable of saving PDF files in 15 minutes

Mozon PDF SDK is very easy to use




 Menu
Home
PDF SDK
    Features
    Download
    FAQ
    Tutorials
    Samples
    Order
Contact Us
About Us
 
 Quick Facts

PDF SDK

MzPDF Toolkit VB.NET Tutorial:


Click here for API Tutorial

Click here for Visual Basic Tutorial

Click here for Delphi Tutorial

Click here for C# Tutorial


Introduction:
  This tutorial will show you how to integrate Mozon MzPDF toolkit in your own application in less than 15 minutes. After that you will have your application PDF-enabled.

  This tutorial will explain how to create a PDF with 3 pages, each page contains 1x1 inch rectangle using VB.NET.

Steps:

 

1. Open visual studio 2005
 

2. Create new project (visual Basic , Windows application)
 

3. Open Form1.vb.

4. Add:
Imports MZDocument


5. Add the following inside Form1 class

Const page_height_inch As Double = 11
Const page_width_inch As Double = 8.5

6. Then add the following function
 

Public Sub GeneratePDF()

End Sub



7. Now, we will do some work inside this function. Define PdfOptions class and fill it with PDF options:

Dim pdfOptions As PdfOptions
pdfOptions = New PdfOptions()
pdfOptions.Title = "Rectangle docment"
pdfOptions.Subject = "Inch rectangle"
pdfOptions.Author = "Auther - me"
pdfOptions.Keywords = "Keywords ..."

pdfOptions.Pdfcompress = True
pdfOptions.Jpgcompress = True

pdfOptions.PdfGenerateImage = True
pdfOptions.PdfGenerateText = True
pdfOptions.PdfGenerateGraphics = True

pdfOptions.PdfShowToolbar = True
pdfOptions.PdfShowMenuBar = True
pdfOptions.PdfShowWindowUI = True

pdfOptions.PageNo = 2 'open PDF in page 2
pdfOptions.Version = PdfVersion.OneDotThree 'version 1.3
pdfOptions.Magnification = PdfMagnification.Custom
pdfOptions.CustomMag = 50
pdfOptions.PageMode = PdfPageMode.Thumbs
pdfOptions.PageLayout = PdfPageLayout.TwoLColumn


8. Now define MZDocument class as the following

Dim doc As MZDocument.Document = New Document()

9. Add progress function:

AddHandler doc.Progress, AddressOf Progress ' ProgressEventArgs

10. Now create the document

doc.CreateDocument()

' Create 3 pages so we need for loop

For i As Integer = 1 To 3

   ' Define PDF Info
   Dim pageInfo As MZDocument.PageInfo = New PageInfo()

   ' Start the page. with 8.5 by 11 inch.
   doc.StartPage(Document.LastPage, page_width_inch, page_height_inch, pageInfo, 0)

   ' Calculate 1 inch rectangle .
   Dim rectangle As Rectangle = New Rectangle(CInt(1 * pageInfo.xDPI), CInt(1 * pageInfo.yDPI), CInt(1 * pageInfo.xDPI), CInt(1 * pageInfo.yDPI))

   ' Create black pen
   Dim pen As Pen = New Pen(Color.Black)

   ' Draw the rectangle on the PDF DC
   pageInfo.PageGraphics.DrawRectangle(pen, rectangle)

   ' Close this page
   doc.EndCurrentPage()

   ' Repeat 3 times

Next i

' Close the document.
doc.CloseDocument()

' Generate PDF
doc.GeneratePDF("c:\\RetanglePDF.pdf", pdfOptions)

' After finish everything delete this document
doc.DeleteDocument()


11. Add progress event function

Public Sub Progress(ByVal sender As Object, ByVal e As ProgressEventArgs)
    Dim currentPage As Integer = e.CurrentPageProgress
    Dim totalPage As Integer = e.CurrentPage * 100 / e.TotalPage
    Dim str As String = String.Format("Page : {0} of {1} ", e.CurrentPage, e.TotalPage)
    Application.DoEvents()
    If (False) Then
        e.Cancel = True
    Else
        e.Cancel = False
    End If
End Sub


12. Go to project settings the to references and add MZDocument.dll for win32 or MZDocumentx.dll for x64


13. Add new menu item call generate PDF then double click on it to create its function, instead this function add the following code

GeneratePDF()

14. Run your application and click the menu item you created in step 13. Then go to C:\ drive you will find RetanglePDF.pdf document was created with the options that you've already chosen.



Note for x64 project, you need first to create new x64 project config from configuration manager
 


Full code is here
 


 

Imports MZDocument

 

Public Class Form1

    Const page_height_inch As Double = 11

    Const page_width_inch As Double = 8.5

    Public Sub Progress(ByVal sender As Object, ByVal e As ProgressEventArgs)

        Dim currentPage As Integer = e.CurrentPageProgress

        Dim totalPage As Integer = e.CurrentPage * 100 / e.TotalPage

        Dim str As String = String.Format("Page : {0} of {1} ", e.CurrentPage, e.TotalPage)

        Application.DoEvents()

        If (False) Then

            e.Cancel = True

        Else

            e.Cancel = False

        End If

    End Sub

 

    Public Sub GeneratePDF()

        Dim pdfOptions As PdfOptions

        pdfOptions = New PdfOptions()

        pdfOptions.Title = "Rectangle docment"

        pdfOptions.Subject = "Inch rectangle"

        pdfOptions.Author = "Auther - me"

        pdfOptions.Keywords = "Keywords ..."

        pdfOptions.Pdfcompress = True

        pdfOptions.Jpgcompress = True

        pdfOptions.PdfGenerateImage = True

        pdfOptions.PdfGenerateText = True

        pdfOptions.PdfGenerateGraphics = True

        pdfOptions.PdfShowToolbar = True

        pdfOptions.PdfShowMenuBar = True

        pdfOptions.PdfShowWindowUI = True

        pdfOptions.PageNo = 2 'open PDF in page 2

        pdfOptions.Version = PdfVersion.OneDotThree 'version 1.3

        pdfOptions.Magnification = PdfMagnification.Custom

        pdfOptions.CustomMag = 50

        pdfOptions.PageMode = PdfPageMode.Thumbs

        pdfOptions.PageLayout = PdfPageLayout.TwoLColumn

        Try

            Dim doc As MZDocument.Document = New Document()

            AddHandler doc.Progress, AddressOf Progress ' ProgressEventArgs

              

            doc.CreateDocument()

            'create three pages

            For i As Integer = 1 To 3

                Dim pageInfo As MZDocument.PageInfo = New PageInfo()

                       

                ' Start the page.

                        doc.StartPage(Document.LastPage, page_width_inch, page_height_inch, pageInfo, 0)

                        Dim pageRectangle As Rectangle = New Rectangle(0, 0, CInt(page_width_inch * pageInfo.xDPI + 0.5), CInt(page_height_inch * pageInfo.yDPI + 0.5))

 

                'OR (Same result)

                        'Rectangle = pageInfo.RectPage;

                       

                'use page info DPI to calculate the drawing rectangle.

                        'Draw 1 inch rectangle.

                        Dim rectangle As Rectangle = New Rectangle(CInt(1 * pageInfo.xDPI), CInt(1 * pageInfo.yDPI), CInt(1 * pageInfo.xDPI), CInt(1 * pageInfo.yDPI))

                        Dim pen As Pen = New Pen(Color.Black)

                        pageInfo.PageGraphics.DrawRectangle(pen, rectangle)

                        'close current page

                        doc.EndCurrentPage()

                    Next i

                   

                     doc.CloseDocument()

                    Try

                        doc.GeneratePDF("c:\\VBRetanglePDF.pdf", pdfOptions)

                        Catch documentException As DocumentException

                            MessageBox.Show(documentException.Descreption, "Error")

                    End Try

                    'delete document handle to clear

                    doc.DeleteDocument()

                    Catch documentException As DocumentException

                    MessageBox.Show(documentException.Descreption, "Error")

           End Try

    End Sub

 

    Private Sub GenereatePDFMenuItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenereatePDFMenuItemToolStripMenuItem.Click

        GeneratePDF()

    End Sub

End Class




 

Download MzPDF Toolkit:

  The MzPDF toolkit (Evaluation version) can be downloaded from the downloads page.

Order MzPDF Toolkit:

  To order MzPDF toolkit, go to the order page.

Note: MzPDF Toolkit is royalty free.

Contact Us:

  If you have any notes or questions please drop us a line and we will be glad to help.

PDF SDK to generate PDF files quickly and easily

Home . PDF SDK . Contact Us . About Us

Copyright © 2011 - Mozon Software