Create PDF in VB Source Code


The PDF format is very commonly used. However, its hard to create PDF files in VB. In the past you had to usually resort to buying a third party control. Before you dish out the cash for a control you should check out this sample source code. It uses the mjwPDF class to generate PDFs from within VB for free. This is a simple sample that shows you how to add text to a PDF file, save it, and view it. Its very well commented. The mjwPDF class allows you to do much more than this. Still this source sample gives you a good basic understanding. After seeing this be sure to check out our other PDF sample source code or read our Creating PDF Files in Visual Basic tutorial to see a step by step guide to creating PDF files from Visual Basic.

If you have any ideas on how to improve this VB6 PDF sample source code please let me know. Also please rate this sample using the form below. Tell your friends - they don't need to pay for PDF creation anymore!

Download the VB PDF sample source code.

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

picturebox to pdf

How to print picturebox to pdf?

print out barcode fonts to pdf file using vb6

Dear Sir.
Thank you for your information to make pdf file.
So I have one more question.
In my report.
I must print out barcode font to that pdf file.
So I try to modify mjwPDF-class by add more barcode font.
then run report
So error message appear .

Barcode font don't exist.

so pls support to me to do with this error.

I'm looking for your support.
Thank you

Text Reports to PDF

Just getting started, but the Class looks Great. I have Text File Reports with everything Headings, PageNo, etc. Is there a basic example of taking the text file and doing line-by-line printing into the Class; OpenDoc, PrintLine(s), EndPage, NewPage, EndDoc are the basic needed function and how to manage advancing down the page.

How do I use mjwPDF-class in VBA

How do I use mjwPDF-class in Excel VBA? Need assistance.

error in mjwPDF class

i am using mjwPDF class to create my report in pdf format, it is working very nice but here i am facing a problem that is when generated PDF file e.g test.pdf exist in the directory whose name contain a space like "d:\my project\test.pdf" then there is an error rais after generating pdf file that is "THERE WAS AN ERROR OPENING THIS DOCUMENT. THE FILE DOES NOT EXIST" AND " THERE WAS AN ERROR OPENING THIS DOCUMENT. THE PATH DOES NOT EXIST . when the directory name has no space it works fine like "d:\my_project\test.pdf" . please tell me how could i solve this problem. CAN ANY ONE HELP ME?

Hello sir, can i use this

Hello sir,

can i use this class to load the text in a pdf file to a visual basic string?????


protected pdf

I want toconvert already created PDF file to save / copy protected pdf using VB6. Can someone share the source code for this with me?
Thanks in advance

Continue PDF Document

Dear Frieds,

I tried this and it is very good. Thanks for the tutorial and source.

But I got a problem when I write to PDF,

if my text is longer than the PDF document, the PDF NOT continue to the next page (Means going down over the page NOT to the second page)

Please help me to solve that problem

Thanks to All

Rename Existing PDF files

Dear Sir,

I want to create a program in VB that picks existing pdf files from one location, rename it and save it to another location.

Thank you

hi kindly help me i did one


kindly help me

i did one project in excel macro (vba), but i forgot the passwrod which i gave.

any one can help me how to crack my macro password.

hello, i don't know if you

hello, i don't know if you got help regarding your protected excel file
if you still need help please communicate with me. if you can send the file , i will open it for you and send it back


My PDF file appears exactly the way intended. However, Upon reading it in Acrobat an error is encountered.
"The font' ._Helvetica-Bold contains a bad /BBox". The font that is actually being used is courrier and is not bold.

Is there something I'm doing wrong? Is there a way to remedy this error condition?

plz Help

How can i remove password of PDf file, actully i want to save a password protected file so that any one can view that file in vb6

jump to bookmark

plz help me. using ur code of create pdf. how can i directly jump to specific bookmark.

Sir, please help.. str1 =


please help..

str1 = "this is a sample text" & vbcrlf & " sample text"
objPDF.PDFTextOut iTest str1

This is a sample text sample text.

I want this result:
this is a sample text
sample text

- why vbcrlf is not working on this sir?

Hi, do you have a solution

Hi, do you have a solution for this?


this below example is work correctly in VBA; you can try it in vba in any microsoft office applications, but in VB if its not work, u must change your Component (add component)

Sub shm_VBCRLF_Test()

Dim strView As String
strView = "this is a sample text" & vbCrLf & " sample text"

MsgBox strView

strView = "My Name is: " & Chr(10) & " Hossein"
MsgBox strView

End Sub

How to use pdf file in vb6

i want to use pdf tool in vb project but i donn't get the syntax, i it work but after closing the project ,the form will not open again.
please sir, help me out .Is very urgent .thank you

re: How to use pdf file in vb6

you must add the class module file (mjwPDF.cls) to the project and then you can use it. project -> add class module -> existing -> mjwODF.cls

to all who thinks this code sux: try to use your head. most features can be handled with it. not perfect, but better than paying $50 or more.
i only have 2 problems with it so far: automatic new page feature and a users guide are missing

Works Slick

I converted the code to MS Access as we don't have VB here at work so I had to play around with it to get it to work and I still have more work to do on it yet; but with a little tweaking it creates a PDF just fine.

The only down side I can see is that the class isn't commented so it takes time to figure out what each routine is actually doing - but heah, I can't complain after all I didn't have to pay for it :)


hi, I was looking for some

I was looking for some kind of code that could merge my access reports in a pdf file.
actually i save 14 reports and is very hard to join them in a sub report.
do you know if it is possible to use this code in vba to do what i want?


it did not work in acrobat

it did not work in acrobat reader 9...

remove it

this project is dum.

do not download it

creating pdf file

How we can convert text file to pdf file using visual c++ ?

Please reply.

vb 6.0

this article contains fucking bad info.dun read it
it will definately bore u off

pls help...

can u give sample program using OLE,DATA, COmbo box and timer..

pls help...

can u give sample program using OLE,DATA, COmbo box and timer..

Thank you very much for the

Thank you very much for the tutorials!

More power!

Great Job

You've done great job. Thanks. Really...
It needs some copyrighting :-)

Acrobat version compatibility

I created an application in VB6 using the PDF creator on a Win2000 server with Acrobat Reader 7. When I deployed the application on a Windows XP it worked find. Now that the reader has been upgraded to version 9, the application crashes when calling it.

Are there any compatibility issues between the PFD creator and the different version of the Reader?


I was checking the code and I see this PDFImage :

So everyone that want to put image in PDF file can use this code :

objPDF.PDFImage App.Path & "\Cradle_Of_Filth.jpg", 5, 5

app.path = Its the address of your application

Cradle_Of_Flith = Its my pic , you should use your pic , Notice "The extension of it must be jpg or jpeg"

First 5 : Is X Position of your pic in PDF
Second 5 : Is Y Position of your pic in PDF

copy image to pdf

Dear Sir,

I have multiple pictures. How to copy them into multiple pages in a pdf file?
Thanks in advance..

Great work

Dear Sir,

Thank you so much for sharing your expertise on this forum.

Techie's like you make our life so easy !!

God Bless

How to convert PDF to text file

cud u plz send me the code for converting pdf into txt file.

Thanks!! in Advance.

PDF Image and text

Is there any way using this module to set an image as the background of the PDF file and have the text on top of the image?

Thanks in advance, really looking forward to using this, if it can do the above mentioned functionality!

employee information

i need some code "read unlimited employees names and their salaries and findout the highest salary getting employee's name".

security feature

thanks for your source code in creating pdf files in VB 6 but my boss isnt satisfied with our current report generation. is it possible to set our newly created pdf file security that no one cannot edit our newly created pdf file? thanks in advance.

project about encrytion and decryption

hi friends,
Does anybody know how to encrypt and decrypt all kind of files(text file, image file, pdf file, ect,....) using a single visual basic or c++ source code program.
This is very urgent plz assist me by imparting some references or by your own program.

Is there a way to do this

Is there a way to do this with an Adobe control that is reliable? I've used two "Free" PDF conversion programs and they both lock up a few percent of the time and I get phone calls in the middle of the night every couple of weeks when they fail.


Merging PDF

Does anyone know how to merge a PDF and an Image in VB6

saving text file to pdf file


I'm using the example code for saving a text file as a pdf. All works ok except the incoming text contains carriage returns which seem not to convert. For example:

This is my test.
To send to a pdf file.

is saved and displays after convert in pdf reader as

This is my test. To send to a pdf.

Any ideas?


SS SOMEONE should tell me the full meaning of PDF and also define it for me. i need ur help. i have heard so much abt it but dont know it. i would also like to b using it in my programs. THANKS

Meaning of PDF

It means "Portable Document Format". It is widely used because you can open it on any computer that has a PDF software and the fonts used don't have to be installed on that computer. The fonts that are not on your computer will be opened as bitmaps instead of text, so you can read it on any computer with the software. The most widely used PDF reading software is Adobe Reader. Acrobat can also read and create PDF from other formats.

RE:I don't Know the meaning of PDF

ITS Pure Durable File........

PDF - Portable Document

PDF - Portable Document Format


Hi How connect the Msacces to PDF (in VB)



PDF Module-Total number of pages

It's a wonderful class. It helped me a lot. I could not figure out how to print the Total number of pages on the page footer as in
'(currnet page number) of (Total pages)'. Kindly help.
Thanks in advance.

Using VB6 to create PFD File

Hi there,
I am trying to extract transactions from table and write it to PDF document using VB6 and doesn't know how to do it. Could some please share with me the VB6 scripting that does that ?




even i am trying for the same thing.if you find it moving please let me know

VB - PDF module

It was a great module...
It works to make a pdf file, but the program become unstable, then an error report show up.
Maybe there is some process never end, i can't find it where.
Can u send me new fixed tutorial sample with more explanation in sourcecode view?
thanx, it is really good module

inserting fonts folder using access

Hi I am using MS access code builder, I could insert the mjwPDF class file but was unable to insert the FONT folder. Any help please.
Thanks Judson



Thanks for the nice tutorial

Thanks for the nice tutorial and source code.

great source - 10X!

great source - 10X!

Subcript out off range

When I try to create several PDF files after another, i get a Error message Subcripts out off range in de class module even if i use objPDF.PDFinit.

Is there a freindly way to avoid this type off errors ? Great Class by the way.


use class variable as private

use class variable as private variable...

New Fonts

Did you ever figure out how to add more fonts? We need to have a lot more font options but I have not been able to add any yet.

PDF ClassModule

Great work!
I looked through he comments and was surprised too see that nobody asked anything about graphics inclusion. Typically professional (PDF) documents contain several graphics (letterhead, logo etc.)

Can it be done?

How to convert a word document to pdf using the above app

Hi there,

In the above application a text is hard coded in the source code itself for example : "Hello World". Can you tell me how can i select a word or excel document and then convert the same into pdf format using the above application. Thanks for your help in advance


It looks like the script I need. How can I use it in 2008

Great Source!

Thank you for this source, i was looking all around, and finally i found here what i was looking for!

Thanks Daniel / Germany

PDF Module

Thank you.............................!!!!


Its great and helped me a lot...............thanks for ur help.

about class PDF module

Hi there,
It was great to use this module to do what i want to do but is there any way it can do wordwrap as i have long description which should be displayed complete with a word wrap.
Thank you