Creating PDF files in Visual Basic


PDF stands for portable document format. It is a format that every operating system on virtually any computer can read. Its become the default standard for transferring and viewing files in an easy way. The problem is that Visual Basic has no built in VB6 PDF functions. Because of this it has been very hard in the past to create PDF files from VB. Hopefully by the end of this Visual Basic Tutorial, PDF creation will be an easy thing for you to understand and do first hand.

PDF is a pretty complex data format. Because, of this usually you have to buy a third party control from someone who's invested a large amount of time in navigating through the PDF format and written an easy way for you to access it. This tutorial explains how you can create a simple PDF file without a third party control. If you run into limitations down the road you might still end up having to purchase a control. However, you will then know exactly what to look for in the control and know how much you are willing to spend to get the functionality you need. Hopefully you won't even need to purchase one. If there is something you are trying to do, add a comment here or in the forum, and we will try to help you with it. Also there is a followup to this tutorial: Creating Advanced PDF files using Visual Basic. It goes a lot more in depth into things like adding pictures, headers, page numbers and bookmarks.

The first thing you will need to do to follow this tutorial is to download the mjwPDF class and the PDF fonts. This class allows you to easily create PDF files and is what we will be using in this Visual Basic Tutorial. PDF creation is a snap once you've downloaded the class. Now copy the class and the fonts folder to the area where you have your project saved.

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
        ' 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 ("
    ' End our PDF document (this will save it to the filename)
End Sub

Lets walk through this code so we know what it does. I've added comments to explain each section. First we create the mjwPDF class object. We set a title for the PDF file. This will show up if someone looks at the file properties for this PDF document. Next set where the document will be saved. We are just saving it as test.pdf in the same folder as our program is. Next we tell it where the fonts folder is located. This is why we had to copy that folder to our running directory. The class uses this information to add those fonts to the file when they are needed.

The next line (line 13) is completly optional. By specifying true, our PDF document will be opened once we finish writing to it. Obviously on many applications you simply want to save the document and not show it to the user. If this is the case set this property to false.

Starting at line 16 we get into the meat of this Visual Basic tutorial. PDF file creation is a simple step by step process. First we decide what font we want. What size it is and if we want any special characteristics (like bold or italic). Next we set the color we want our text to be. Lastly we call the PDFTextOut to actually write the text to the PDF file. NOTE: I am saying write the text to the PDF file, but really its simply stored in a buffer until we call PDFEndDoc. We do this next and that is when all of the buffer is actually saved to the filename you specified in line 7. Also, since we set the PDFView property to true the PDF file is then opened for us automatically and we can see a simple file with our text added to it.

Download the VB PDF tutorial source code and have fun! Please leave comments below as to how well this worked for you. Also, I have written another tutorial: Visual Basic and Advanced PDF Documents. It goes a lot more in depth into how to add pictures, shapes, headers, hyperlinks, multiple pages, and page numbers.

Note: The original source code for this class (before modifications) can be found here.

If you enjoyed this post, subscribe for updates (it's free)

Run-time error '70' SOLVED (but...)

Hi to all,

the error is caused from this piece of code:

    If boPDFView Then
        PDFScanRepAdobe "C:\Program Files\", 0
        If wsPathAdobe <> "" Then
            iRet = Shell(wsPathAdobe & " " & PDFGetFileName, vbMaximizedFocus)
        End If
    End If

1. Starting Windows Vista and next Windows versions the permissions has changed.

2. Path is wrong, because work ONLY for english language of Windows
i.e on Windows XP ITALIAN language the correct path is: C:\Programmi\

3. The class try to get the Acrobat Reader path to view PDF, but this is a wrong way because user may not this reader installed.
Therefore need to use ShellExecute() API function, instead of Shell().
Note che ShellExecute() open any file using the default program set by user. I.e. if user use FoxitReader, then FoxitReader will be used to view the PDF file.

To solve the problem apply these changes:

Into class module mjwPDF add this code:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Function OpenPDF(ByVal psFilePDF As String) As Long
    OpenPDF = ShellExecute(0, "open", psFilePDF, vbNullString, vbNullString, 1)
End Function

In PDFEndDoc method, comment the part of wrong code:

'    If boPDFView Then
'        PDFScanRepAdobe "C:\Program Files\", 0
'        If wsPathAdobe <> "" Then
'            iRet = Shell(wsPathAdobe & " " & PDFGetFileName, vbMaximizedFocus)
'        End If
'    End If

then add this lines

    If boPDFView Then
        iRet = OpenPDF(PDFGetFileName)
    End If

Now it work. :-D

However, despite these corrections, the VB-PDF-source project prints a blank page, and the PDF remains in a state of 'modified'. When I close it asks me to confirm the changes.
I do not know the reason, I hope that the author will remedy. ;-)

Instead the other project Advanced-PDF-Tutorial works fine, but...
when I close it asks me to confirm the changes. ROTFL.

I work on:
- Windows 7-64bit/SP1
- VB6.0/SP6

my web site: VB Corner (

Run time error 70 and Modified state

Excellent work - would have saved my self several hours trying to migrate to Win 7. Had resorted to hard coding the Adobe path in a ini file. Works flawlessly now. You will still get the error 70 if you leave the reader open to the same file. I do not get an extra page. The state is "modified" because there is an error in the PDF file which Adobe fixes on the fly. Note that the original test.pdf is 4K but is 6K after saved by Adobe. I have another application that pukes on the original test.pdf.

Thanks again for your good work!

Adobe asking to confirm the changes

I believe there is an error in the "hello world" test file that Adobe v11.0.4) understands and corrects on the fly. This is why the state is "modified". You will notice that the input file is 4k and the changed file is 6k in length.

I have another application that is not as clever as Adobe. It reports
There was an end error while parsing the PDF file. The PDF is likely corrupt or invalid.
at ceTE.DynamicPDF.Merger.Pdf(Document.e()
at ceTE.DynamicPDF.Merger.Pdf(Document..ctor(fu A_0, String A_1)
at ImpacMosaiq.UI.DocumentViewer.ucViewer.MergeFilesToPDF(String FilesToMerge,String SavDIR)

I remain excited about this software and do hope to use it in a large VB6 application.
Thanks very much.


VB PDF Conversion

Dear Sir / Madam

I am using your code in my vb application. I want design report but i am unable to set width of the line. The thickness of line is quite high. The code i wrote is objPDF.PDFDrawLineVer 2, 5, 20. Please suggest me appropriate procedure to write line in PDF file.

Use Bullzip, download and

Use Bullzip, download and install bullzip pdf printer(free) then on your vb project references it will show up, check them all.

VB PDF Conversion

Dear Sir / Madam

I am using your code in my vb application. I want design report but i am unable to set width of the line. The thickness of line is quite high. The code i wrote is objPDF.PDFDrawLineVer 2, 5, 20. Please suggest me appropriate procedure to write line in PDF file.

Run-time error '70':

This message always occur whenever i try to run it:

Run-time error '70':
Permission Denied

Private Function PDFScanRepAdobe(sPathBegin As String, iIndexFolder As Long) As Boolean

If oFolder.Attributes <> 22 Then
For Each oFiles In oFolder.Files
-------> If InStr(1, oFiles.Path, "AcroRd32.exe") <> 0 Then
wsPathAdobe = oFiles.Path
bScanAdobe = True
Exit For
End If
Next oFiles
End If

Do I really have to recreate all my reports?

I currently have a project that contains over 30 reports that were created with the printer.print command. I do not want to have to recreate the reports. Is it possible to take the data sent to the printer and before it prints have it redirected into a PDF?

Thnk's a lot...

Thnk's a lot...

Cnvert MS Word documents to .pdf

Great stuff! I'm impressed. What I would like to see is also a way to actually convert an existing MS Word documnt to .pdf. I my case, I have a large VB6 program that among other things handles Word documents from our library, or in some cases creates Word documents. It would be so nice to be able to convert finished Word documents to .pdf from within my VB6 program.
Any possobillities of adding such code into your class?
Yes, there are numerous converters out there doing conversion, but they all come with their own user interfaces. You can even save documents as .pdf documents from Word. But again, I want to make the conversion from within my program. Thankful for all hints on this.


I would like to draw splines and closed curves using mwjPDF.
Please help me...

Rao Bhaskar


I would like to draw splines and closed curves using mwjPDF.
Please help me...

do not run in windows 7 64 bit os

sir it's not working in 64 bit os,,, whwn i click the button the pdf file doesnt show/ how can i fix it


Can this VB project run in Ms Access VBA?

Change a languaje

Thank you very much!
I have one problem: I need to use a Russian font in the project, as it is possible to change the font to a Russian? I have strange characters are displayed

Thank you again!

Adding new fonts -> Bad bbox

Hey all.

I converter some ttf fonts to afm.
Put them in the fonts folder and can create a PDF.

However, now get a PDF error "Font contains bad /bbox".

Any ideas?

kembreg at y!

mjwPDF Manual

Hi there.

Quick question -> Does anyone know of a user manual for this class?
i.e. a description of all the subs and properties.
That would be great.


Can a print Data report in VB 6 in pdf format?

i have a vb 6 application and generating reports (data reports), but these reports could only be saved in "html" or "text" format.
is this possible to generate data reports in pdf format?
can any one help me in this regard?
please share any example/ sample vb 6 code to display and save data reports in pdf format.
thanks in advance


vb 6.0

please send vb6.0 setup

it doesn't work


I copied the code. But it doesn't work. The error "member data not found" always appear.. pertaining to the line "objPdf.PdfTitle"

I hope you could help me solve this.


Watermark semi-transparent

First of all, thanks for the code. I use it a lot in my VB6 app and works quite well. I am using the PDF.Watermark property, but wondered if you knew how to create it with some kind of semi-transparent factor?

print the created pdf (for vb tutorial pdf)


How to print the just created pdf through vb6?

That is so true PDF files in Visual Basic As an author and business man, I like how you said "PDF stands for portable document format. It is a format that every operating system on virtually any computer can read". I hope more people discover your blog because you really know what you're talking about. Can't wait to read more from you!

how to creat pdf file through vb6 with Access data

How to creat pdf file through vb6 with Access data ????
plz. detail

Error in opening by reader (error 14)

What's this. Who can help me?

When I try to open test.pdf with Acrobat Reader 9, I see an Acr.Reader's blank page with report:

error on opening file (error 14) file corrupt.

WindowsXPsp3 + Acrobat Reader 9


Thank you

Try adding the uncommented

Try adding the uncommented code at the end of the PDFEndDoc subroutine.
At least for me this finds my default PDF viewer (Foxit rader)

If boPDFView Then

' PDFScanRepAdobe "C:\Program Files\", 0
' If wsPathAdobe <> "" Then
' iRet = Shell(wsPathAdobe & " " & PDFGetFileName, vbMaximizedFocus)
' End If
'ShellExecute Me.hWnd, "open", App.Path & "\your.pdf", vbNullString, vbNullString, SW_SHOWNORMAL
ShellExecute lngHandle, "open", PDFGetFileName, vbNullString, vbNullString, SW_SHOWNORMAL
End If

Still got error (14)..

Hi Sir..
I've try adding the above uncommented, but I still got the same error.
Could you help me on this..?

Many thanks and Regards.

hey genius!

.. How can set the text to the next line if it is in the end line.. THank you so much!!

How to Set PDF version in the output PDF

I am using a vb application which generates a PDF using Acrobat Exchange, however the version of Adobe Acrobat I am using is Acrobat 9.0 and I would like the output PDF generated to be PDF 1.4. Is there any explicit API to set the version of the output PDF in the VB program itself to 1.4 as currently it is generating PDF 1.6 with Acobat 9.0?

Code to convert pdf file to jpeg using

Code to convert pdf file to jpeg using

You absolutely rock!! thanks

You absolutely rock!! thanks a bunch

PDF files in Visual Basic

I've found this... can't figure out what the syntax is to actually call the subroutine though.

Sub Export(FileName As String, Extension As String, [SelectionSet As SelectionSet])
Member of DWGeditor.Document
Exports the file to any of the supported formats. Optionally, pass in a selection set to export only a part of the file. Format is based on the extension in the FileName (default is the DXF format).

I was thinking something like:

error 70 with windows 7

Listings in PDF work fine with Windows XP but run the program with windows 7 gives error 70, and breaks the program. Please .. help me

need source code for softwae develop in vb 6.0

Any body help me to develop shop bill software in visual basic 6.0

Your PDF tutorial in VB6

I downloaded the tutorial and ran it. Then I began to write different things with different fonts. Everything works just fine.
I undertsand that this code works perfectly well to create a PDF from scratch.

My question is how can I write over an existing PDF?
I will give you a very simple example. I receive a printed page (single sided) with three lines of text on it
First line: one digit number
Second line: "Box(xx) YY" [xx YY are doubel sigit numbers]
Third line: LastNeme, FirstName, date of birth, five digit ID number
I scan this page and produce a PDF file

How can I possibly add a fourth text of line that would be the PDF file name itself?

I know how to get the file name: Cuerda$ = Dir$(Path$+"*.PDF")
Where in the PDF format do I find the appropriate place to insert new text into an existing PDF i did not create myself in the first palce?

How do I subscribe to your forum???

how to set password to pdf file


How do we set password to pdf file?


Help with the Shell Command

I have written a program in VB5.0Pro and it uses a shell command to run a bat file opening a certain page in an Adobe reader. PDF File It works by running the bat file ok. It works using a shell command with Borlands Turbo Basic Program but will not work with VB. Please can you help !! The Shell comand will run other programs ok so the path is working. Adobe does not seem to like something is comes up with an error and says it needs to close every time.


I got run-time error 70. Help!

Hey I like to make a magazine


I like to make a magazine by PDF ... So how will the interface of the magazine will be ?
Help for Ideas

Thanks all



I think this is really cool.

Can you also insert images?



I have some interest in using this pdf function in an application. Could you fill me in on rights with respect to font data? Thanks.

Getting AddPageNumber Error


i have seen in coding a line which shows AddPageNumber but while runing the programe that is the main erro... pls advicxe me what is AddPageNumber??????

Re: Happy

Hi All Users.......

I'm the new User and recently I registered.
I'm gettinhg great thanks to evryone which connects with ur special queries???????

Thanks withamling...urs..

jpeg not written


So far I can get this to work, except for any jpeg file which is not embedded in the pdf. The pdf is made without error, but is only 312 bytes big...
Any idea?



ok, pilot error... Figured

ok, pilot error... Figured that when only wrapping a jpg image in a pdf it wasn't necessary to include the fonts. Not so...
It works now.

Best, vis

VB 2008 - doesn't work.

Hi, this looks incredibly useful for a yr 12 project i am doing - is there another version anywhere that will work with vb 2008? When i try and run it i get heaps of errors - mainly just incorrect declarations and incorrect syntax.

Thank you in advance.

wooowww,,, greattttt,,,

wooowww,,, greattttt,,, b(^_^)d

but How can i make the table with an array ???
like this...

| No | Name |
| 1 . | xxxxxxxxxxxxxxxxxxxxxxx |
| 2. | yyyyyyyyyyyyyyyyyyyyyyyy |
| N. | zzzzzzzzzzzzzzzzzzzzzzzz |

but with the true line..
thanx for respect,,,


objPDF.PDFTextOut ("--------------------------------------------------------------"), 1, 1
objPDF.PDFTextOut ("No." & Space(6) & "Name"),1,2
objPDF.PDFTextOut ("--------------------------------------------------------------"), 1, 3

Multi lines?

How can we have two line in our PDF document?
for example we have a textbox and we want to copy it's text to a PDF and textbox is:

and ...

Thanks a lot

Converting DOC Files

I have some DOC files that I want to programatically transform into PDF files.
How can this be done?


I have run the program but show error 19 if any help me I will remain thanks


I faced troubles too. But the error number was 70.

Creating PDF files in Visual Basic

Great stuff - and really appreciated. Just happened to stumble on it and Hey Presto a lot of my problems solved.
Many thanks.


I would like to draw splines & closed curves using mwjPDF class.
I hope you have the solution...
Please help me.

What's your Adobe Reader

What's your Adobe Reader version?

GOOD JOB! I 'll use

I 'll use this code on my new project.!

Tables in PDF

The tool is great !
Can I create a table of rows and columns with this great tool?


I tried inserting database files on the pdf and it works. thanks

Private Sub Command1_Click()

Dim xTotAl As Integer
Dim xCtR As Integer
Dim xPage, mCaptioN

mCaptioN = Me.Caption

With Adodc1
.ConnectionString = "Provider=MSDASQL.1;Password=pwd1234;Persist Security Info=True;Data Source=NwindVBP;Mode=ReadWrite"
.CursorLocation = adUseClient
.RecordSource = "Select * From tblProducts"

End With

With objPDF
.PDFTitle = "Test PDF Document"
.PDFFileName = App.Path & "\test2.pdf"
.PDFLoadAfm = App.Path & "\Fonts"
.PDFView = True

' Lets us set see the bookmark pane when we view the PDF
.PDFUseOutlines = True


.PDFFormatPage = FORMAT_A4

' Lets add a heading

' ProductName
' SupplierID
' QuantityPerUnit
' Unitprice
' UnitsOnOrder


xCtR = 75
xPage = 0

Do While Not Adodc1.Recordset.EOF
'------------------------left, height
Me.Caption = "Reading file/s .." & Adodc1.Recordset!ProductName

.PDFTextOut Adodc1.Recordset!ProductID, 20, Str(xCtR)
.PDFTextOut Adodc1.Recordset!ProductName, 75, Str(xCtR)

If Adodc1.Recordset!SupplierID <> "" Then
.PDFTextOut Str(Adodc1.Recordset!SupplierID), 285, Str(xCtR)
End If

.PDFTextOut Adodc1.Recordset!QuantityPerUnit, 335, Str(xCtR)
.PDFTextOut Str(Adodc1.Recordset!unitprice), 415, Str(xCtR)
.PDFTextOut Str(Adodc1.Recordset!UnitsonOrder), 460, Str(xCtR)

xTotAl = Val(Adodc1.Recordset!unitprice) * Val(Adodc1.Recordset!UnitsonOrder)
.PDFTextOut Str(xTotAl), 520, Str(xCtR)

xCtR = xCtR + 10

If xCtR >= 790 Then
xPage = xPage + 1
AddPageNumber objPDF, Str(xPage)
xCtR = 75
End If


xPage = xPage + 1
AddPageNumber objPDF, Str(xPage)


End With

Me.Caption = mCaptioN
'Unload Me
End Sub
Sub xHeaders()
With objPDF
.PDFSetDrawColor = vbRed
.PDFSetTextColor = vbWhite
.PDFSetAlignement = ALIGN_CENTER
.PDFSetLineWidth = 2
.PDFSetFill = True
.PDFCell "Product/s Description", 15, 15, objPDF.PDFGetPageWidth - 20, 20, ""

.PDFSetTextColor = vbBlack

'------------------------left, height
.PDFTextOut "Product ID", 20, 60
.PDFTextOut "Product Name", 75, 60
.PDFTextOut "Suppliers", 285, 60
.PDFTextOut "Q/Per Unit", 335, 60
.PDFTextOut "Unit Price", 405, 60
.PDFTextOut "Units Order", 450, 60
.PDFTextOut "Total", 520, 60

End With
End Sub

Database access example

Thank you for this useful example

I found that the units used in this example require an initialization to make it work well.

Use objPDF.PDFSetUnit = 0 to set the units from cm to points

Really awesome

Thanks alot for this, very nice.
I wish to know whether it's possible to produce txt file from a pdf file.In short is it possible for me to read my PDF file and return a corresponding txt file in vb6.Thanks in advance

Thank you~

Thanks a Lot~~~~~~

VB PDF Tutorial

Just downloaded it, tried it, and it works. Amazing stuff. Many, many thanks. This should give me hours of entertainment.

VB PDF Tutorial

Do you really succeed? Can you help me?


honestly, i have no idea in using visual basic yet. i downloaded your code and simply run it. i also tried modifying the lines such as hello, world ..... and it worked!!! i am so amazed that i started appreciating the significance of vb. just wanna ask you how to add some lines... i tried to write some lines including your hello, world but there's an error. what should i do for me to add some lines if ever?

load code of the file in the vb6.0 on run_time

Hello.Can you say me how to create a program with these details:
form1 (for load code)
form2 (with command1 and label1 in the form without any code)

Form_Load of Form1 should send the code from "c:\a.txt" (or other address) to the form2 (in the run_time)

c:\a.txt :-------------------------------
dim count as integer
private sub form_load()
end sub
private sub command1_click()
end sub

Please put it's source file to download . "Thank You"

Error in opening by reader (error 14)

Hi, great class! Thanks

When I try to open test.pdf with Acrobat Reader 9 show me a blank page and report and error on opening file (error 14) file corrupt. I tryed also Acrobat 4.0 but is the same.

Any suggestions?
Thank you



very very thanks

very very thanks

error in the above code,, plz help me

i m getting error in SETHEADER function ,,, in this line
strm.WriteLine "%PDF-" & mjwPDF



accesso negato


ho scarico ed eseguito le istruzioni del tutorial e tt ok, però quando quando lo eseguo mi dice autorizzazione negata....come posso fare??

Very very nice contribution

Very very nice contribution in the web....

Both bold and italic font

How do I set the font to be both bold and italic for the PDFTextOut function?


I think you should specify

I think you should specify "FONT_BOLD Or FONT_ITALIC".
Don't know, just try it.


how to add data in pdf from textbox?

how i can add data from textbox to pdf?
here only code for providing fix string or data.
please help me on this topic and send me code on my email.

If you can't figure this

If you can't figure this out, you probably shouln't be coding at all.

Try this code:

objPDF.PDFTextOut (txttesting.Text), 1, 1
objPDF.PDFTextOut (txtname.Text), 1, 2
objPDF.PDFTextOut (txtisa.Text), 1, 2


The Number there is the x and y axis of the PDF..

Display image from Picture

I want to display image in PDF File not from *.jpg but from obj.Picture. It's possible...

Best Regard


most picture load fails come

most picture load fails come from people not relizing that .picture is a place holder not a local data hold

try loading the picture to a image file then root your code product from image to picture

like :
image.path = "some file"
picture1.pic = image1.picture

picture1.picture = pdfobj.picuture or (whatever)

picture1 loads fail most commonly because they are orignaly designed to be used as buffers
some people will tell you its the global local call idea that caused all this its not...
there buffers.. ever wonder why a computer will just strart running slow after a while.
its because most programmers dont know this...

it seems like its not importiant but computers run at funny speeds
the double load under images allows the processor to set it self for new information
instead of guessing what is to come next and creates the higher resolution speed machine process
allowing the computers ai to catch its next idea. this all has to do with vb's API code,,,,,
next just remember that vb works this way because the creators new about the machine code
and vb being known as a beginner language. they put many small work arounds like this in place
to option place markers for study.. I am quoteing all this from a book I have on vb and by memory
so sorry if its a little complicated.

Can any one help me to make

Can any one help me to make a program to search and open specified files using vb 6.0, c++6.0 or Visual Fox Pro 6.0

alignment prblm in class file

some alignment prblm using arial font

how to solve

Thats great

Thats great

I tried this tutorial and

I tried this tutorial and it's very straight forward I will try the advanced lesson
thank you very much for this.

Stand Alone

Hi there,
Is ghostscript a requirement for the mjwPDF Class to work?
Many thanks...

Invoice Printing In PDF

Creating A invoice to visual basic as output as PDF please help to create them

textbox text into PDF

hello there.)

can some one teach can i make text in the textbox appear in the PDF file..?

hope can help..

sorry my writing..?

Multi-Page PDF File

First of all, thanks for a great tool. I have the following situation. When I create a multi-page PDF file and it's presented for viewing with the Adobe Reader the document is presented at the bottom of the last page instead of at the top of the first page. Is there some way within the VB code to have the document presented at the top of the first page? Thanks.

(Note: I get the same result if I open the file directly with the Acrobat Reader. However, if I open the file directly with the NitroPDF program it is presented starting at the top of the first page.)

Multi-Page PDF File

I've figured it out. In the Class Module find the PDFSetCatalog Sub. In the code for PDFZoomMode you will see four statements that have "/ OpenAction [3 0 R ......" in them. Change the 3 to 1 in all four statements.

This resolved the situation. The displayed document now begins at page 1, both within the VB application and when the file is opened directly with Adobe Acrobat.

As an aside, why would the default ever be to display the document beginning with the last page?

Error path not found

I am getting a path not found error.
The debugger highlights this line:
Set oRep = Fso.GetFolder(sPathAFM)
in the routine:
Property Let PDFLoadAfm(sPathAFM As String)

Can someone help with this?

Maybe because sPathAFM is set

Maybe because sPathAFM is set to "C:\Program Files" and you are working with a Windows version other than English.
i.e. for Spanish you should search the source and change "C:\Program Files" to "C:\Archivos de programa"

Please help me.

Hello everyone,

I am so impressed of what i saw on your example. Actually I have a project that have a similarity on your tutorial but then i saw myself so difficult because I am so new on developing a program and gaining some idea for it because i develop the program in web. My problem here is, how can i convert the .jpg file to .pdf file? Please help me sir/mam... and i really appreciate it your kindness...



Awesome ~ cheers !!! How

Awesome ~ cheers !!!

How about populate data into PDF template file?

Excellent Tutorials

Thank you for this great tutorial .. I can say that I have checkout many sites related to vb6 but none like this one.. good job

Greetz from Mexico

Default Page

Hello, I think you have done a fantastic job with this class. I have one question though that I have not seen asked here. I am making multi-page PDF documents, but when they are opened in the acrobat reader it always opens to the end of the document. I didn't see any obvious functions to make it open to page 1. I would appreciate any help you can give me as it is very important that the document opens to page 1. Thank you, I appreciate it

Accents. How?


I like to print spanish text like "plátano" but isen't print correctly because dosen't works with accents.

How to solve?

Thanks in advanced,

for pdf convert

Sir, i want to write more than one lines in pdf file,please send me the code of more than one line write on pdf file.

write more than one line on pdf

Write this line in a loop:

For i = 1 To 10

Next i


For Each tmp2 In tmp
objPDF.PDFTextOut _

tmp is an array

Create a PDF document with the page in landscape orientation.

Hi, can anyone please help me.
I have read the tutorial and have managed to create a PDF document and insert a JPEG picture in to the document.
This is largely due to the very good tutorial which has been posted.
I have been given a task to create a PDF document and insert numerous JPEG's. The problem is that all the imported JPEGs must be in landscape orientation. I need to change the orientation of the PDF sheetr from portrait to landscape. I have tried to change the orientation property value within the mjwPDF class but this has no effect and the JPEG continues to be in portrait form.

Can anyone shed any light on this issue, on how to change the page orientation using the mjwPDF class.

Thanks a lot.
David Curran.

Can I create a PDF File from a template


Hope anyone can help me. I wonder if I can create a PDF File using this component, but based on a template, so I just can print some text and preserve de rest of the text from the template.

thanks in advance.


Excellent post.I want to

Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work. great ,thanks


This is a very goo example.

Thanks a lot...

I must salute the efforts you have put into this website... This article is very helpful...

thanks for the tutorials. it

thanks for the tutorials. it helps. its additional info that i could teach to my students

Watch Battery


Kode-kode yang bagus, terima kasih atas tutorialnya. Sangat membantu sekali.

convert other fonts

how to convert other windows standard fonts to your *.afm format ?
you have any tool for this conversion ?

You are my Mentor Dr.

I have been following your VB tutorial and your explanation is so wonderful. It has never be explained to me like this before. I hope be very good in it with your teachings.
Thanks alot Doc.
Godwin, Nigeria

Thank you

This is very good.

And rather than complain or ask someone else to help sort out the more minor issues - I did it myself.

Great work, fellah!


good , But ...

that is good module
but i modefied some thing on it i made it not open adobe reader after generating the file .

thank you

terima kasih.....

line break in pdf

how to introduce line breaks in the pdf that is created using this code?


How do I make my database report to be displayed in pdf format, please help me.

Thanks for your anticipated support,

Search capability in pdf file from VB

After converting text to pdf file from VB, I need to open pdf file with search option. This gives an error "There was an error opening the document. bad parameter.

Adding text line by line

This porgram is really good! unfortunately, when i add additional text on the second line and so forth it did not write the value of the . PDFTetOut!
I will create textboxes and pass the value to the PDFTextOut each line but it is not working! I really need help.. Thanks

Reg Use of this class


I want to use this class in my VB application to generate PDF reports.
Please let me know if i can use it or not. I will be very thankful to you.
Waiting for ur response.


PDF Draq

Nice Class, it works great.

Having trouble with something. I can write any text with out any trouble but if I Draw some lines and then I start again with text. This last one would not be display in the PDF no error, no massage. It´s like if I haven´t sent any pdftextout.


sir good tecahing in our

sir good tecahing in our people

Figure it out

The problem was with de objpdf.pdfdrawrectangle, if I draw the rectangle with .pdfdrawlinehor and .pdfdrawlinever problem solved

thank anyway for this great Visual Basic 6.0 tutorial pdf.

view PDF as text

i have a question: how to read/preview/convert pdf as text file like some application preview pdf file?

And Format PDF - PDF-A

It's amazing this code...

This file is create in format PDF, of course.

How I do to create in Format PDF-A?



how to get the path from C:\"my folder name"

hi...i quite impress with your far i already tested it and it work properly!
i want to apply your code in my program but the problem is i already has word document and once user click will automatic generate the pdf file from that word file.
Can you help and teach me on how to make it work??
thank you for ur co-operation..


need help

good day siti..)

i am amature programmer..)..i very need your help to solve this problem..

i do not know why...when i trying to run the program which is create the PDF using VB6, the PDF document did not appear..they did not tell any error on coding, no debug..

i am just follow the whole step by step..unfortunately it is not working..

if you know something wrong somewhere with this..let me know..i appreciate it..

please I want to use this Visual Basic 6.0 tutorial pdf.

PDF Document

Its fine, Really a nice one. But it doesn't show document in more than one line.
objPDF.PDFTextOut "My Second PDF File" objPDF.PDFTextOut "My Second PDF File"
I have written it two times still it doesn't work
how to solve?

hei there is an error on

hei there is an error on line 24 they say method or data member not found what should i do

Print form to pdf

It is great tool ,

I did it successfully,

My Question is:

I want to print the form to pdf.

Thank you


Hi There,

What a great class!!!! One question.

I have data in a acess database that I want t write to pdf.
I will get my data like this:
Dim rs as New Recordset "Select * from Clients", CL, 1, 2
Do while not rs.EOF
this is where I need Help

Can You Please assist?



I want a code to read

I want a code to read text from pdf file can you help me


All coordinates in the examples use the top left as 0,0.
I want to use it to produce a graph, so it makes it much simpler if 0,0 is bottom left.
How can I change the default?

Thank you.

its urgent

Gautam here
its urgent
the tutorial was quite good but an error is occuring while i'm running it
the error is:
User-defineed type not defined

Error 91

I keep getting Error 91, it stoped whenever Strm.WriteLine TempStream is used. Any idea??


Little bug for lacalized computers


Here, in France, computers use the comma instead the point as the decimal séparator
in the PdfSetPageObject, you shoud use

PDFOutStream TempStream, "<< /Type /Page"
PDFOutStream TempStream, "/Parent " & ParentNum & " 0 R"
PDFOutStream TempStream, "/MediaBox [ 0 0 " & _
Replace(CStr(PageCanvasWidth(CurrentPDFSetPageObject + 1)), ",", ".") & " " & _
Replace(CStr(PageCanvasHeight(CurrentPDFSetPageObject + 1)), ",", ".") & "]"
PDFOutStream TempStream, "/Resources " & ResourceNum & " 0 R"

Thank you for your contribution, dear French friend.

It's not only in France. All the world where French, Spanish, Portuguese and Italian (at least) are spoken, use the comma
as the decimal separator.
This is hundreds of millions of people.

Now, in the age of globalization every programmer must think in terms of world, and not in terms of "home".
That's the reason why Unicode was invented.

By the way, you there, in France, invented the "Meter", "kilogram", "litre", and so on...
All the world accept that immediatly, except the english-speaking contries, who still use
the "yard", "mile", "pound", "foot", "gallon", etc. WHY ?

Your contribution is very useful, bacause in my computer the program didn't work at all, until I read your post, and you
save me hours (if not days) catching a very tiny bug, but that made all the difference.

Thank you


Question regarding this visual basic 6.0 tutorial pdf:
I would like to know If I can Open existing pdf documents and wright to them.


thanks for the pdf vb6,appreciate

Opening existing PDF

I'm trying to open an existing PDF, add a page number and print. Some comments above suggest tht mjwPDF can not open existing files. Is this correct. If so, could you please suggest a freeware or commercial VB library that supports this.


Displayed PDF File

The generated PDF file is displayed at 37.1%. Is there a way in my code to have it displayed at a higher percentage, say 75% or even 100%. I realize the size can be changed with Adobe Reader once the file is displayed but I'd prefer to have it presented originally at a larger size. Thanks.

BTW, this is a great tool -- great function and very easy to understand and use.

Display PDF File

I've looked at objPDF.PDFSetZoomMode. There are options for FULLWIDTH and REAL which produce a 100% display. However, for my application these create something that is too wide. There doesn't appear to be a capability for setting a percentage such as that in Adobe Reader. I need 50% or 75%. Any way to do that in code?

Display PDF File

It would be beneficial to have something like objPDF.PDFSetZoomMode = ZOOM_PERCENT, X -- where "X" is the desired percentage for the display.. If done I assume that the specified percentage would have to be one of those supported by Acrobat Reader.

Rich Text Content in PDF

I have gone through your tutorial. Nice.
I need to create PDF with Rich Text.
Bold, Italic, Lines etc.,

Im getting "there was an error opening this document"


Im getting "there was an error opening this document" this file cannot be found...i have saved the pdf class in the same folder where i saved my project file....please give me a using the VB 6 version.
Thanking u

PDF internal link

Thanks for this class. It will be so usefull.

Is there a way to create a link that points to another page in the same PDF document?

Merci encore,


Multiple Line to be printed


It is working wonderfully, but i am facing problem while inserting logo in beginning fo the pdf doc and then data in multple lines from a text box.

Else it is perfect.

can you post the pdf file

can you post the visual basic 6.0 tutorial pdf file that is created. I got the class to create the file but Acrobat shows there is problem reading the document. I would like to find what the error is by comparing your pdf file with mine.

Thanks for the excellent article.

Never mind. I corrected the

Never mind. I corrected the errors and converted it to VS 2008.

is it possible the contents

is it possible the contents of the pdf are from data in database??

For text file to PDF

I am new to this PDF class that it's what I am looking for. I have two questions:
1: I have a text report created using Notepad, Now I want to open it directly using this PDF class object, how to do it?
2: I have a word file with images inside it, how can I show them in PDF?


Hi, I read through the text

I read through the text file line by line and write to pdf file, it works fine.
At first I was failed because I tried to open the text file then use READALL to write the whole contents in text file to pdf, the error is overflow.

I have a question, I use LANDSCAPE for page orientation, line space use 1.0, in this condition there are only 20 lines allowed each page. How can I control lines of each page? how can I make sure the pdf file is opened with 100% zoom? now it's 74%.



Hi. Just to let you know I appreciate your making this code available.
Worked "out ot the box" and I simply modified it slightly to automatically locate the location of the Program folder.
A quick question: does it handle mixing text and graphics in complex arrangements?
Best regards

VB 2008?


Do you have something likes this that works with Visual Basic 2008 Express edition?

I try'd this but it doesnt work :D

mail me?