Creating Advanced PDF documents in VB

Level:
Level3

In the previous tutorial we looked out how to create a simple PDF document that was one page and was only text. If you've seen many PDF documents on the web or elsewhere you know that they usually include more than just text. Fortunately we are able to do these things as well. In this VB PDF tutorial we're going to look at how to further use the mjwPDF class accomplish what we need. By the end of the tutorial you should be able to create a multi-page document that has headers, footers with page numbers, shapes, graphics, and web links.If you want, you can download the source code for this VB PDF tutorial and follow along with it.

If you haven't read the introductory tutorial about Creating a PDF document using Visual Basic. Please do so first. This VB tutorial builds off the previous one. In fact to start with lets look at the code we created before:

  1. Private Sub Command1_Click()
  2.     ' Create a simple PDF file using the mjwPDF class
  3.     Dim objPDF As New mjwPDF
  4.    
  5.     ' Set the PDF title and filename
  6.     objPDF.PDFTitle = "Test PDF Document"
  7.     objPDF.PDFFileName = App.Path & "\test.pdf"
  8.    
  9.     ' We must tell the class where the PDF fonts are located
  10.     objPDF.PDFLoadAfm = App.Path & "\Fonts"
  11.    
  12.     ' View the PDF file after we create it
  13.     objPDF.PDFView = True
  14.    
  15.     ' Begin our PDF document
  16.     objPDF.PDFBeginDoc
  17.         ' Set the font name, size, and style
  18.         objPDF.PDFSetFont FONT_ARIAL, 15, FONT_BOLD
  19.        
  20.         ' Set the text color
  21.         objPDF.PDFSetTextColor = vbBlue
  22.        
  23.         ' Set the text we want to print
  24.         objPDF.PDFTextOut "Hello, World! From mjwPDF (www.vb6.us)"
  25.    
  26.     ' End our PDF document (this will save it to the filename)
  27.     objPDF.PDFEndDoc
  28. End Sub

Great. With this code we've done all the initializing and created a basic file. Now lets add some formatting options. Right after we set the fonts folder lets add a few lines of code that tell mjwPDF what the document layout should be like.

  1.     ' We must tell the class where the PDF fonts are located
  2.     objPDF.PDFLoadAfm = App.Path & "\Fonts"
  3.    
  4.     ' Set the file properties
  5.     objPDF.PDFSetLayoutMode = LAYOUT_DEFAULT
  6.     objPDF.PDFFormatPage = FORMAT_A4
  7.     objPDF.PDFOrientation = ORIENT_PORTRAIT
  8.     objPDF.PDFSetUnit = UNIT_PT
  9.    
  10.     ' View the PDF file after we create it
  11.     objPDF.PDFView = True

This code sets up a standard page (letter size) in portrait orientation and our units of measure as points.

Next lets do something fun. Often times you want to add a heading to a PDF document such as "Very Important Report Blah Blah" Lets figure out how to add a heading such as this to our document. Delete the bold lines of code below:

  1.     ' Begin our PDF document
  2.     objPDF.PDFBeginDoc
  3.         ' Set the font name, size, and style
  4.         objPDF.PDFSetFont FONT_ARIAL, 15, FONT_BOLD
  5.        
  6.         ' Set the text color
  7.         objPDF.PDFSetTextColor = vbBlue
  8.        
  9.         ' Set the text we want to print
  10.         objPDF.PDFTextOut "Hello, World! From mjwPDF (www.vb6.us)"
  11.    
  12.     ' End our PDF document (this will save it to the filename)
  13.     objPDF.PDFEndDoc

And add these lines of code in their place:

  1. ' Lets add a heading
  2. objPDF.PDFSetFont FONT_ARIAL, 15, FONT_BOLD
  3. objPDF.PDFSetDrawColor = vbRed
  4. objPDF.PDFSetTextColor = vbWhite
  5. objPDF.PDFSetAlignement = ALIGN_CENTER
  6. objPDF.PDFSetBorder = BORDER_ALL
  7. objPDF.PDFSetFill = True
  8. objPDF.PDFCell "A centered heading", 15, 15, _
  9.     objPDF.PDFGetPageWidth - 30, 40

Let me explain what these mean. You should recognize the first line of code. It just sets the font info. Next we set the DrawColor (which in this case will be the highlight or inside color of our box). Next the text color is set and our alignment and border. The PDFSetFill=true tells mjwPDF to fill this box in when it prints out our text. The next line is what displays it all.

Let me break it down. The first parameter is simply the text we want displayed. Next we tell it how far over from the left we want the box (or cell) in our case we said 15 points over from the left. The next parameter is 15 points down from the top. Next we have to specify how wide the box is going to be. We want it to stretch all the way over to the right side of the page (minus the 15 point right border). To accomplish this we can use the mjwPDF classes PDFGetPageWidth function. This will give us the full width of the page we then subtract 30 off of it (15 for the left border and 15 for the right border), the last parameter is the height of the cell, 40 will be plenty high to accommodate our text.

If you run the code you should see your PDF pop up with a beautiful header at the top of the page.

Another fun thing is to create shapes in your PDF files. This can be used to create bar graphs or to highlight certain areas. Here is some sample code that creates a square.

  1.         ' Lets draw a dashed red square
  2.         objPDF.PDFSetLineColor = vbRed
  3.         objPDF.PDFSetFill = True
  4.         objPDF.PDFSetLineStyle = pPDF_DASHDOT
  5.         objPDF.PDFSetLineWidth = 1
  6.         objPDF.PDFSetDrawMode = DRAW_NORMAL
  7.         objPDF.PDFDrawPolygon Array(300, 150, 400, 150, 400, 250, 300, 250)

Most the settings are self explanatory. Notice that you can specify the line style and the line width. Also notice that there is no draw square function. Instead there is a draw polygon function. It takes one parameter, but that parameter is an array of points specified in x y coordinates. X being how far from left to right to draw the point and Y being how far from top to bottom. So in our example we are specifying 4 points (the four corners of the square).

  • Point 1 is 300 pixels to the right, 150 pixels from the top
  • Point 2 is 400 pixels to the right, 150 pixels from the top
  • Point 3 is 400 pixels to the right, 250 pixels form the top
  • Point 4 is 300 pixels to the right, 250 pixels from the top.

Next lets draw an ellipse. An ellipse is simply a circle that can be squeezed either vertically or horizontally. To define it correctly we have to use some mathematical terms. If you remember from geometry class a circle has a radius. The radius is the distance from the center of the circle to the edge of the circle. An ellipse has two radiuses. One is horizontal the other is vertical. So the code for our ellipse is this:

  1.         ' Lets draw an ellipse
  2.         objPDF.PDFSetDrawColor = vbYellow
  3.         objPDF.PDFSetLineColor = vbBlack
  4.         objPDF.PDFSetLineStyle = pPDF_DASHDOT
  5.         objPDF.PDFSetLineWidth = 1.25
  6.         objPDF.PDFSetDrawMode = DRAW_DRAWBORDER
  7.         objPDF.PDFDrawEllipse 300, 150, 75, 25

All the parameters should make sense by now. The new line is the PDFDrawEllipse call. Its a very simple call except that many times you think the x and y coordinates would correspond to the center of the circle. However, you would be wrong. Instead the first to parameters correspond to the upper left corner of the square that bounds the ellipse. The next two parameters specify the horizontal radius and the vertical radius respectively. If this seems confusing just run the program and you will see what I mean. The x & y parameters for our ellipse are the same as the x & y parameters for our first point in the square so you will see how it works. If you run the program you should see this:

Lets step back to text manipulation in PDF documents again. One thing you usually see in a professional document is the header like we did above. Another thing is usually page numbers in the footer. We can use the same logic we used for our header to add page numbers. I would like to add the numbers in the footer of the page on the right side, like most documents have. I'm not going to walk through how you can do this step by step, but here is the code for a visual basic subroutine that adds the page number to the bottom right corner of your PDF document.

  1. ' Adds the page number to the current page
  2. Private Sub AddPageNumber(objPDF As mjwPDF, pageNumber As Integer)
  3.     Dim sPageInfo As String
  4.     Dim fontSize As Double
  5.     Dim margin As Double
  6.  
  7.     fontSize = 10       'Size of font to use
  8.     margin = 40         'Size of margin (left, right, bottom)
  9.    
  10.     ' Set what we want to print for page info
  11.     sPageInfo = "Page " & pageNumber
  12.    
  13.     ' Should save these settings and change them back for more robust code
  14.     objPDF.PDFSetTextColor = vbBlack
  15.     objPDF.PDFSetAlignement = ALIGN_RIGHT
  16.     objPDF.PDFSetFont FONT_ARIAL, Conversion.CInt(fontSize), FONT_NORMAL
  17.     objPDF.PDFSetFill = False
  18.  
  19.     ' Uncomment the below line if you want to see how our formatting works
  20.     'objPDF.PDFSetBorder = BORDER_ALL
  21.    
  22.     ' Draw the page number at the bottom of the page to the right
  23.     objPDF.PDFCell sPageInfo, margin,  _
  24.         objPDF.PDFGetPageHeight - margin - fontSize, _
  25.         objPDF.PDFGetPageWidth - (margin * 2), fontSize
  26.  
  27. End Sub

Now that we know how to add page numbers how do we actually create multiple pages? Its very simple. When you are done with the first page, simply call the PDFEndPage method. Next call the PDFNewPage method to start the next page. Than just call the commands to add your text or shapes to the next page. You can do this as many times as you want. Don't forget to call the AddPageNumber method on each page though.

Another useful feature of PDF documents is adding bookmarks. Bookmarks allow you to jump from section to section in a PDF document easily. When the user views a PDF document with bookmarks, they are able to see a table of contents type tab on the left side of the screen. Note: if you want that pane to be visible by default you should add this line of code to the initializing section of your program.

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

Adding a bookmark is very easy in Visual Basic using mjwPDF. For instance lets add four bookmarks to our first page of our document. Call these anywhere in your code before you call the PDFEndPage method.

  1.         'Lets add a bookmark to the start of page 1
  2.         objPDF.PDFSetBookmark "A. Page 1", 0, 0
  3.        
  4.         'Now a bookmark half way down page 1
  5.         objPDF.PDFSetBookmark "A1. Page 1 Halfway down", 1, 300
  6.        
  7.         'Now one at the end page 1
  8.         objPDF.PDFSetBookmark "A2. End of Page 1", 1, 500
  9.        
  10.         'Another one a little further down and shows nesting
  11.         objPDF.PDFSetBookmark "A2-Sub1.", 2, 800

The first call to PDFSetBookmark creates a bookmark labeled "A. Page 1". The next parameter is the depth of this bookmark. Note: Start your depth at 0. The last parameter is the y position to where the bookmark will move the page. So the first call created a bookmark titled "A. Page 1" that points to the top of page 1. The next call creates a bookmark titled "A1. Page 1 halfway down". It has a depth of 1 (so it will be a child under our first bookmark) and it will scroll the page 300 points down. If you run the program you will see all the bookmarks created like this screen shows.

Another necessity to learn when creating PDF documents is how to add images to them. The mjwPDF class allows you to add any .jpg images to your PDF document. If the image is in a different format you will need to convert it to .jpg before you will be able to add it to your PDF file. However, if the image is a jpeg it is very easy to add it to the PDF doc. In the sample source code included with this tutorial you will see a logo.jpg file. Below is the code to end our first page and to start our second page. On the second page we add our logo to the upper left corner of the page.

  1.         objPDF.PDFEndPage
  2.        
  3.         'Start page 2
  4.         objPDF.PDFNewPage
  5.        
  6.         'Lets add an image to page 2
  7.         objPDF.PDFImage App.Path & "\logo.jpg", _
  8.             15, 15, 50, 50, "http://www.vb6.us"

The highlighted code is what adds the logo. We call the PDFImage function. The first parameter is the path to the jpeg file. The next two parameters are the x and y coordinates for the logo. The next two parameters specify the width and height of the image. These parameters can be left off and then it will just display the picture in its original size. You can also specify just the height or width and it will scale the other side of the picture to keep it in proportion. The last parameter is also optional, but it allows you to specify a web site to go to if someone clicks on the image.

If you run your program now you will see a PDF file that has all the properties of a complete PDF document. Headers, shapes, images, and page numbers. Combining all these techniques you should be able to do just about anything you would want to. Download the Advanced PDF VB Tutorial source code to see the full sample.

Why would I buy a PDF control?

This is a common question. Although the mjwPDF class does allow you to do some pretty cool things you still may wish to buy a control for one or more of the reasons below:

  • You need to add other images besides JPGs on the fly.
  • You want to compress or encrypt your pdf file.
  • You need code that is more optimized for memory space or processor speed.
  • You need support from a reputable company.
  • You just like spending money for fun

If you get to a point where you do need to buy a PDF control I can probably recommend one to you. Send me an email and I can help you out. Otherwise if the mjwClass works for you feel free to use it. I would still ask you to send me an email just so I know what your using it for. Thanks.

Comments

Image handling enhancement

I'm sending plain raw images to a PDF without text and so I needed to make sure the image was fit to the page. In the existing code, if the image size was larger than the page, the edges would be cut off. I added some code so that if the image width and height were unspecified (ie. 0), then the image would be resized to fit to the page dimensions:

In the PDFImage sub, change the following code from this:

    If w = 0 And h = 0 Then
        w = ArrInfo(0) / in_Ech
        h = ArrInfo(1) / in_Ech
    End If

to this:

    If w = 0 And h = 0 Then
        w = ArrInfo(0) / in_Ech
        h = ArrInfo(1) / in_Ech
        If w > PDFCanvasWidth(in_Canvas) Then
            w = PDFCanvasWidth(in_Canvas)
            h = w * ArrInfo(1) / ArrInfo(0)
        End If
        If h > PDFCanvasHeight(in_Canvas) Then
            h = PDFCanvasHeight(in_Canvas)
            w = h * ArrInfo(0) / ArrInfo(1)
        End If
    End If

I also added this code for centering, but it may have other undesired effects, such as not allowing an image to start off the left of the page:

Right after the following code in PDFImage:

If w = 0 Then w = h * ArrInfo(0) / ArrInfo(1)
If h = 0 Then h = w * ArrInfo(1) / ArrInfo(0)

put this code:
    If y < 0 Then y = (PDFCanvasHeight(in_Canvas) - h) / 2
    If x < 0 Then x = (PDFCanvasWidth(in_Canvas) - w) / 2

When you want to add a full page, centered image use the following command:

    objPDF.PDFImage sFilename, -1, -1

If you want to use the command like it was before, just specify the other parameters:

    objPDF.PDFImage sFilename, 0, 0, 50, 50

run-time error when using PDFSetBorder = BORDER_BOTTOM

I have the following lines of code in my project:

objPDF.PDFSetFont FONT_ARIAL, 6, FONT_normal
objPDF.PDFSetDrawColor = vbWhite
objPDF.PDFSetTextColor = vbBlack
objPDF.PDFSetAlignement = ALIGN_LEFT
objPDF.PDFSetBorder = BORDER_BOTTOM
objPDF.PDFSetFill = True
objPDF.PDFCell "0000000", 329, 35, 70, 9

And am getting the following error at run-time:
Run-time error 13: Type mismatch

The error is occurring on this line in the mjwPDF class module:
If PDFstrTempBorder = "LRTB" Or PDFstrTempBorder = 1 Then

And I find that if I change my pdfsetborder property to either BORDER_NONE or BORDER_ALL, the run-time error disappears, but if it is set to BORDER_LEFT, BORDER_RIGHT, BORDER_TOP, or BORDER_BOTTOM, I get the run-time error.

Any idea what would cause this? Is this is a program bug?

Thanks,
Kevin

Great stuff

I have a question though. How can one access an already existing pdf and pull out text and pictures. Is it just the reverse of opening it and trying to read the text or is there something else?

Thanks

how to write pdf file using sql query record set

how to write pdf file using sql query record set

thanks in advance

Vikas Verma

add data of a TEXT-BOX to PDF

how do i add the data of a TEXT-BOX,in vich which the user will write data..to a PDF file..
plzzz help man..mail me the soln.
thanks in advance

Other fonts for PDF file creation

Truly great tutorial and example for learning about creating DPF files in VB. Is there, or would you consider writing, some tutorial on how other fonts could be used for creating PDF files?

I have spent a considerable time researching available documentation on the PDF file format specifications and experimenting with your code, but so far I've had no luck (I consider myself to be a quite advanced VB expert, although real professionals would likely consider me a diletant).

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

Default Page Solution

Default Page Solution :

Salut,

Dans la procédure PDFSetCatalog, j'ai remplacé les instructions :
"/OpenAction [3 0 R ..."
par les instructions :
"OpenAction [1 0 R ..."
et cela fonctionne ...

Congratulations to mjwPDF Class !

Default Page Solution

Would someone please translate this to English and fill in the "....". Thanks.

Default Page Solution

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?

Thank you Tom! I was going

Thank you Tom! I was going to try and figure out this out today and you saved a ton of time!

Hi ! "Thank you Tom !

Hi !
"Thank you Tom ! ..."
And no thanks for SergeL ???

Adding code 32 font

I need write PDFs with barcodes, i found the code39 afm file and put it in the Font directory, but i don't know very well how can i add the font to the project to use it.

I was reading the class methods and i think that only can use the default fonts. I modify some lines of the class to add the new font but the method PDFGetStringWidth launch this error: "Runtime error '9', subscript out of range" in the line "ArrFNT(aAsc(1)) = Int(aWX(1))".

May be the code39.afm not correct?

Please Help me !!!

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.

windows Vista

I tried your class in several examples, and has always worked, since I'm using Vista does not work anymore! crashes in this part of code:

Private Sub PDFEndStream()

Dim TempSize As Long

TempStream = TempStream & sTempStream
If dTempStream <> "" Then TempStream = TempStream & dTempStream
sTempStream = ""
dTempStream = ""

PDFOutStream TempStream, "endstream"
PDFOutStream TempStream, "endobj"
PDFOutStream sTempStream, "%FIN_OBJ/%"

StreamSize2 = 6

PDFAddToOffset Len(TempStream)
Strm.WriteLine TempStream '***** ERROR!! "Permission denied".

TempSize = Len(TempStream) - StreamSize1 - StreamSize2 - Len("Stream") - Len("endstream") - 6
ContentNum = CurrentObjectNum
CurrentObjectNum = CurrentObjectNum + 1
TempStream = ""

PDFOutStream sTempStream, "%DEBUT_OBJ/%"
PDFOutStream TempStream, CurrentObjectNum & " 0 obj"
PDFOutStream TempStream, CStr(TempSize)
PDFOutStream TempStream, "endobj"
PDFOutStream sTempStream, "%FIN_OBJ/%"

PDFAddToOffset Len(TempStream)
Strm.WriteLine TempStream

End Sub

and tells me "Permission denied".
The same code on Win XP works fine!
Do you have experience of this case?

Vista is troublesome - Get Windows 7

Where are you saving your files i.e. which folders?

Vista is notoriously troublesome because they have blocked every access by the user except the Administrator.

If you have written an application that save data to the typical windows directory i.e. such as "program files" then you may have this permission problem.

My suggestion, try saving your application to "common files" folder.

extract the fonts en the file PDF

youyou have can extracting fonts the file PDF .... PDF to Fonts..? think you.
f

This is helpful. But how do

This is helpful. But how do i open the current(saved) pdf file and write into it? help is much appreciated

Very nice information

Very nice information manMelissa, this article realy help me. Thanks it really looks promising! Your blog is one of the most wonderful places to visit.

Help pls, to open a pdf file and print it programatically?

Can someone help me please. Assuming I have 2 printers setup on mydesktop. Printer1 is a Black and white and Printer 2 is Color. Printer1 is the default printer. I wanted my VB Program to open the pdf file and automatically select Printer2 (Color) for printing? I am using Microsoft Print Dialog reference in my project to bring up the printer dialog box.

converting pdf file to word document in vb

Dear friends,
i need help to convert a pdf file to a word document using vb, pls can anyone help me to do this,
if so pls mail me on thanusree@ncssoft.in
thanks

Using a diferent Font

I'm using the class to create a PDF report. It works fine while I use the fonts provided with the sample code. I used TTF2PT1 utility to convert the Calibri.ttf Font to an afm file. It seems to work good. I create the PDF report well but when I open it, a message saying "The Calibri.afm Font contains an erroneous /Bbox" Of course I did the corrections to the code for it. Can anyone help what to do for solve this? I'll appreciate your best help.

Query for multiple lines in pdf

hello, ur code is great. but it writes only 1 line to pdf file. howdo i write entire vb6 form in pdf? pls guide me.

help

hello, ur code is great. but it writes only 1 line to pdf file. howdo i write entire vb6 form in pdf? pls guide me.

Restricting editing

Hi, I'm trying to find out how to restrict editing of the PDF.
I need this because I convert an Access Report that is A Quotation for a customer to a PDF file.I don't want someone to be able to modify the PDF file by using a PDF writer version.

Thanks

Restricting editing of PDF

Restricting editing of PDF documents is mostly a waste of time if you also allow the document to be printed - as someone can simply print the document to a PDF driver and edit the resulting PDF.
The same applies to people that prevent you copying from a PDF but allow it to be printed - where is the logic in that??

To writte text into existing pdf file using VB6 platform

Could any one can help me in writting the text into a existing pdf file. I mean it to open pdf file and wriiting/ stamping a text and then saving using Visual basic 6.0 platform.

Regards
Jyothis

Writing to a pdf file

Assuming your pdf form allows fill-in, first open the pdf form using Adobe Reader (or other PDF reader), then populate it with unique text strings (i.e., WQPKXZ) as placeholders where you want your real text to go. Then, in your VB6 code, open the file as a binary file and replace the dummy text strings with your VB string variables. Finally, write to (create) a new PDF file containing your changes. Good luck. Example code is shown below:

'------------- below code is to populate & open a PDF Form

Open "C:\Program Files\My Application" & "\Sample_Form" & ".pdf" For Binary As #22
strBytes = Space$(LOF(22))
Get #22, 1, strBytes
'strBytes = StrConv(strBytes, vbUnicode)
Close #22
strBytes = Replace(strBytes, "WQXZName", strName)
strBytes = Replace(strBytes, "WQXZAge", strAge)

Open "C:\Program Files\My Application" & "\Sample_FormFilled" & ".pdf" For Binary As #23
Put #23, , strBytes
Close #23

'Call Shellexecute to open & display PDF form
strFile = "C:\Program Files\My Application" & "\Sample__FormFilled" & ".pdf"
strAction = "OPEN"
lngResult = ShellExecute(0, strAction, strFile, "", "", vbNormalFocus)

'------------- end of code to populate & open Form 4797 pdf

Writing to a PDF

This code is perfect except my PDF document will not allow me to save changes made to the highlighted fields. It only allows you to print a copy. Any ideas? CJF

encrption

Hi,

How can i add password encryption in my pdf?
Pls. help.. thanks.

Multi-Lines

Mulit Line?

I dont know whats wrong with this class but it seem as soon as you pass any text to PDFTextoutput the class ignore or cant handle more text.

When I was tying to print a multi line text it was all one line that the PDF doesnt reconize vba.vbCrLf Vbnewline or any other type of letc.

So I tried this.

Dim MyTmpSting() as String, I as Long
MyPDFString = "Hello from mars " & VBA.vbCrLf & "How are you today? " & VBA.vbCrLf
MyTmpSting = VBA.Split(MyPDFString, VBA.vbCrLf, -1, vbTextCompare)

For I = 0 to 2
On error goto hell
objPDF.PDFTextOut MyTmpSting(i)
next i
Hell:
objPDF.PDFEndDoc

Just an example

Still can only get the One line ""Hello from mars" all other text in the array is ignored.

So is the problem in the class or PDF ?

Does the string need a C+ Return \n ?

Anyone have any ideas?

RichtextBox to PDF

Hey there
Thanks a lot for such a wonderful stuff you provide.
I'm making a small software wherein I have a RichTextBox. The user's gonna write anything in the RTB, any sort of content.

Now What I need is that the user should be able to save the RTB content into a PDF file, on click of a button.
HOW CAN I DO IT?
Also, I don't want the pdf to open automatically, instead it should just save at a particular location provided.

Can you pls pls help me with it....

Thanks in anticipation

Email me at: elton2jain@gmail.com

Hi your codes are great

Hi your codes are great however I am just wondering on how to fully justify the text on the cell?
I have used the left, right and center, is there a way to justify it on both left and right?. Thanks.

Cutting dependancy on fonts

Hi,
This works great. within in seconds it was just what I need and very neat.

I have just one question is it possible to cut out the dependancy on the fonts provided. I notice that Arial is not one of the .afm files provided but everything still works fine when it's called, and this is the only font I need. I'm looking to distribute my file in an excel .xla with as few external files as possible.

Thanks

How to create bookmark using bookmark root

Hi

I have problem with creating bookmarks in pdf file.
I am using below code to create from word document pdf file and want to get bookmarks in pdf based on headers.

Set AcroApp = CreateObject("AcroExch.App")
'Create an instance of a doc
Set ADoc = CreateObject("AcroExch.PDDoc")
'create another instance, which will be used to store the new docs.
Set ADocNew = CreateObject("AcroExch.PDDoc")
Set AvDoc = CreateObject("AcroExch.AVDoc")

'open the first PDF
b = AvDoc.Open(sDirPDF & "\" & aPDFs(0), "")
Set ADocNew = AvDoc.GetPDDoc
'set viewmode to show bookmarks (3=PDUseBookmarks)
AvDoc.setviewmode (3)
'set initial value of bookmarkindex
nIndex = 0

For i = 1 To UBound(aPDFs())
'open next pdf
b = ADoc.Open(sDirPDF & "\" & aPDFs(i))
'get number of pages of the new PDF
iPgLen = ADocNew.getnumpages - 1
'insertpages (after_which_page,what_to_insert,startpg,endpg,???)
b = ADocNew.insertpages(iPgLen, ADoc, 0, ADoc.getnumpages, 0)
'Get JavaScript object
Set jso = ADocNew.GetJSObject
'Set the root of the bookmark tree
Set BMR = jso.BookmarkRoot

BMR.PDFSetBookmark Left(aPDFs(i), Len(aPDFs(i)) - 4), "this.pageNum=" & ADocNew.getnumpages - ADoc.getnumpages, Index
'increase bookmarkindex
nIndex = nIndex + 1
'close the last PDF that was opened - we don't need it anymore
ADoc.Close
'get the filename of the next PDF
Next i

Example:
Table of Content in word document will look like:
1. Chapter Name Specific
1.1 Under Chapter Name
1.1.1 Under Chapter Name
1.1.2 Under Chapter Name
And in pdf file should be avalaible to click on bookmark accordingly.

Do you have any idea how to solve my problem...?
Thank you and regards.
gkoper

Alternative Image Support

Great tool!
I have created a system to automatically generate PDF data reports, emailed to the client before he/she gets to work :). The graphical data plots are, of course, JPGs. And so the client wants more. I am now encountering an issue where the PDF is getting to be too large! Does anyone have code to provide GIF image support? A GIF image is probably a tenth of the byte size of a JPG. Is this possible?

vb6

Hello, I am wondering what the command is for a "next" kind of button like for instance you have a game and when you click a certan button a box will come up (not a small msgbox a box that would be the same size as the main program

Em@il: braduz911@live.co.uk
Please please send me the script asap

PDF in VB6

How do you take a form created in VB6 and dump it in to PDF?
My application uses a form setup as a full A4 page and is used to create invoices etc. I need to save these as PDF

Brillianr, but, how can I......

Brilliant, the answer to my problems, but there are a few things that seem logical to me but I can't find out how to do them.
1. The main problem is the time it takes to create the pdf file, is there any way to speed it up? It takes 15-25 seconds to display. Only an annoyance really not a major problem.
2. When using pdfcell with border_all the text wraps way before the end of the cell leaving masses of white space and consequently uses more lines than necessary to display the text. I got around it by turning off the border and using the polygon to draw the box. Ok but I have to fix the height of the polygon instead of it dynamically growing.
3. Leading on from 2. above, is there any way to determine how high or rather how far down the page text entered using pdfcell has gone? I need this to do 2 things, firstly determine where to place the next polygon and secondly to determine when I need to create a new page. Using pdfcell which wraps is far easier for my purposes than pdftextout.

Any pointers on the above much appreciated.

Again, a really usefull tool, thanks for your efforts.

Tim

Sending generated pdf to printer?

Does anyone know how to send the generated pdf of this class, onto a physical printer (it doesn't matter if it's the system default one).
Currently im using ShellExecute, but even if i change system default printer by hand, it ALWAYS goes to Adobe PDF printer, don't know why.

Plz help!!

pd: if your answer is, buy a control, forget it!

READ PDF

READ PDF
Hi!!!!!!!!
can anybody tell me
How to read pdf file in VB so that i can Store/insert it into database?

tables in PDF

Can any one share code for tables in PDF using this class. I need it urgent

Open pdf file in another pdf file Programatically

Hi All,
We have a requirement in our project. We want to open the PDF document which is contained by another PDF document using VB or VBScript or JS ( the Master document contains several other PDF documents).

Thanks in advance...!!!

Srinivas

Very good this code.

Dear ..

Congratulations... this code it's very easy to use.. simple and efficient. How I create in format PFD/A, it's possible?

Best regards.

Silvio

LOL?

LOL?

Adding a Barcode

Hi
Can anyone tell me how to add a Barcode to the PDF? I do it in VB normally by specifying the appropriate font which is a TTF. This project uses fonts with .AFM extension. Does anyone know where i can get .AFM barcode fonts?
Thanks

YourSolution

hi
contact me for your solution
at
opmishra81@yahoo.co.in
or
omfromranchi@gmail.com

PDF File Creation

Hi
Thanks for the great tutorial on creating PDF files. I have created the files i want but tha last thing i need to do is add a Barcode. I have the barcode font which is a True Type font. How do i use other fonts than those provided with the Tutorial?
Thanks Again

create link to another file

Hi,

Firstly, I have to say that this class it's great!!!! Congratulations!!!
But I don't know how to create a link in a PDF file to another PDF file, saved in a specific location (for example: C:\TEST.pdf)
Thanks in advance.

Ignasi From Barcelona

unable to add fonts folder in access vb editor

unable to add fonts folder in ms access vb editor, can anyone throw some light on this issue.

Regards
Judson

Questions on pdf. and VB

Qn 1:
I have Adobe Acrobat 9.0 Standard. I have a whole bunch of pdf. documents which I'd like to make interactive (or accessible). Can I do this with Adobe Acrobat 9.0 pro? If not what other software (of the Adobe Acrobat family) do I need to do this?

Qn2:
Can anybody tell me what program software developers use to develop Tax software? Can I do this with Visual Basic?

How to print PictureBox

Very good article and helpful. Can you just explain how to include image from pictureBox in the existing app to PDF

Thanks
Amitabh

How can I convert a html code to PDF

Hi,

I have a html document with some images bound with. How can I convert that to PDF using mjwPDF classs.

Any suggestion will be appreciated.
Thanks
Dhirendra

extend message to 2nd page

Hello...
i have a long message around 1 & half pages and i want to write it into PDF.
how can i do that? Because it still appeare in 1 page.
TQ.

Multi-line document

I get the same result. How can I get the long text stationed in different lines? It's staying on the same line, and.... cutting off info.
-KK

MICR Font

We need to create an A/P check that includes the MICR line. The question is can we use this class to print the check number, transint number and account number using the Eflring MICR font on the check we propose to produce?

truetype font and ansi characters

Hi,

Is it possible to use a TrueType font ?
Is it possible tu use a font with ansi characters (dos characters) ?

Add image in PDF

Hi, I getting error when i try to add image into PDF.

I'm getting errror "Insufficient data for an image".

Anyone can help? Thank you.

Hi, Is it possible to use a

Hi,

Is it possible to use a TrueType font ?
Is it possible tu use a font with ansi characters (dos characters) ?

Thank you

This is a fabulous plugin, thank you so much - you have no idea how much time this has saved.
I just spent a week trying to output vb to rtf and html and it was a nightmare.
In one evening all my outputs are pdf, brilliant.

Password

How do i set password protection?
Thanks

RTF to PDF

I've been wracking unsuccessfully for a week now to find and use a simple control or simple methods to merely programmatically convert an RTF file to PDF. Even this class doesn't do it. The best I could come up with is to send the file to my 'printer' which prints into pdf but that still opens the Save As dialog. All I want, all I need, is an object in which I pass in the fully qualified RTF filename and the object converts the rtf file to pdf format. I can even go with passing in a FileListBox that contains the list of files. Any suggestions anyone?

Do it yourself

RTF is a published spec. Read it in line by line into an array, convert as you go and smoosh it out to PDF. Certainly less than a week's work...

Bad Assumption

I'm glad this is here, it really saved my ass. But I did find a bug. On my computer Adobe is installed to drive e:\ and this software assumed it is installed to c:\program files\adobe ... instead of reading the actual install location out of the registry. I made a workaround myself using the registry, but it would be great if the author of this code could add the fix.

-Alex

Change the path accordingly,

Change the path accordingly, check AppPath in the program.

I need to buy PDF Control

Dear

I need to know how can i buy PDF Control because i have trouble to convert TIFF images into PDF with BookMarking. Your Earlier response is appreciateable.

PDF Control

There is no control such like that so dont email again and again .

Convert Tiff images to PDF

Dear
I am in trouble to convert tiff images to pdf. I need your help to give me a PDF Class in VB6 that converts tiff images into PDF. I hope that u will give me a help for that.
Thanks a lot

Malik

This is great, but I do have

This is great, but I do have a question. It may just be my program but when using PDFCell routine, does it indent the first line of the paragraph automatically? and if so where in the code can I turn this off? it Seems to be happening to me.

Thanks again.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post block code using <blockcode [type="language"]>...</blockcode> tags. You may also post inline code using <code [type="language"]>...</code> tags.

More information about formatting options