A very simple PDF

In this first lesson we'll learn how to create a PDF file with the legendary string "Hello world inside". From this moment on, we'll use VB6 as our IDE, but the syntax is IDENTICAL for all other IDEs (Delphi, CBuilder, PowerBuilder...).

The source code of the project can also be found here.

First of all, let's open VB6 and create a new project; add to the project's references the PDFReport_XP library, then draw a button on the form and double click it; inside the event handler skeleton, type this code:

Private Sub Command1_Click()
  Dim PDFRPT As New PDFDocument 
  PDFRPT.NewPDF "This is my first PDF" 
  PDFRPT.TextOut "Hello World!", 10, 10 
  PDFRPT.SavePDF "c:\provaocx.pdf" 
End Sub

The first line declares an Object of type "PDFDocument" and creates an instance of it.

The second line creates within the OBJECT new PDF file (the argument is the string that can be seen in the Acrobat Reader's form caption).

The third line draws the text string "Hello World!" at 10 mm from top and 10 mm from left border of the page. The point of the text from which misuring the distances is the bottom left corner.

The last line saves the PDF file created with the name you want.

The result of this code is shown here: