Blogger Themes

widget
News Update :

Creating PDF files in Visual Basic

Rabu, 11 Mei 2011

If you created a default project (Project1.vbp) and didn't change the name of the form it creates (From1.frm) your project folder should look like this once you've copied the mjwPDF class and the Fonts folder.

If this seems confusing, just download this VB PDF tutorial source code. It has everything zipped into one location for you to see how to set it all up.
Now that the fonts folder and mjwPDF class are in the right spot we need to add the mjwPDF class to our project:
  1. Select Project -> Add File from the menu bar (or hit ctrl-D)
  2. Select the mjwPDF class and click Open

Great. Now add a button to your form. Double click on it and add the following code to it:
Private Sub Command1_Click()
    ' Create a simple PDF file using the mjwPDF class
    Dim objPDF As New mjwPDF
    
    ' Set the PDF title and filename
    objPDF.PDFTitle = "Test PDF Document"
    objPDF.PDFFileName = App.Path & "\test.pdf"
    
    ' We must tell the class where the PDF fonts are located
    objPDF.PDFLoadAfm = App.Path & "\Fonts"
    
    ' View the PDF file after we create it
    objPDF.PDFView = True
    
    ' Begin our PDF document
    objPDF.PDFBeginDoc
        ' Set the font name, size, and style
        objPDF.PDFSetFont FONT_ARIAL, 15, FONT_BOLD
        
        ' Set the text color
        objPDF.PDFSetTextColor = vbBlue
        
        ' Set the text we want to print
        objPDF.PDFTextOut _
            "Hello, World! From mjwPDF (www.vb6.us)"
    
    ' End our PDF document (this will save it to the filename)
    objPDF.PDFEndDoc
End Sub
Share this Article on :

0 komentar:

Posting Komentar

 

© Copyright MeMbLe 2010 -2011 | Design by Herdiansyah Hamzah | Published by Borneo Templates | Powered by Blogger.com.