Solved

how do i convert pdf to jpeg using vb6.0

Posted on 2011-03-14
5
3,071 Views
Last Modified: 2013-11-18
I'm to trying to convert a PDF file to JPEG image using VB6.0

I tried the attached code but when it tries to open the PDF file, I get error Activex Component cant create object.
isOpen = pdDoc.Open("D:\test.PDF")  --------------> errored line

Please advice.
Private Sub Command1_Click()
        Dim pdDoc As New Acrobat.AcroPDDoc    'Acrobat.CAcroPDDoc
        Dim page As Acrobat.AcroPDPage  'CAcroPDPage
        Dim pt As Acrobat.AcroPoint
        Dim rect As Acrobat.AcroRect
        Dim data As Object              'IDataObject
        Dim bmp As System_Drawing_Bitmap                 'Bitmap
        Dim strPathString As String
        Dim isOpen As Boolean
        Dim lngNumPages As Long
      
        
       isOpen = True
       
        ' Begin creating the pdf
        isOpen = pdDoc.Open("D:\test.PDF")
      
              page = Nothing

              doc.Open ("D:\test.PDF")

              page = doc.AcquirePage(0)

                pt = page.GetSize()

                rect = New Acrobat.AcroRect

                rect.Top = 0

                rect.Left = 0

                rect.Right = pt.x

                rect.bottom = pt.y

            Call page.CopyToClipboard(rect, 0, 0, 100)      
            data = Clipboard.GetData()                      
             bmp = data.GetData(DataFormats.bitmap)
             bmp.Save ("D:\test.jpeg")
               
End Sub

Open in new window

0
Comment
Question by:KimberelyB
  • 3
5 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 35136285
I dont have acrobat pro or the ActiveX but there are some issues with your code.

1/ always Turn on  Option Explicit  ... it saves simple mistakes.

try this.
Option Explicit      '<<< first line of module/form

Private Sub Command1_Click()
        Dim pdDoc As Acrobat.AcroPDDoc    'Acrobat.CAcroPDDoc
        Dim page As Acrobat.AcroPDPage  'CAcroPDPage
        Dim pt As Acrobat.AcroPoint
        Dim rect As Acrobat.AcroRect
        Dim data As Object              'IDataObject
        Dim bmp As System_Drawing_Bitmap                 'Bitmap. <<<< NOT VB6. this is .NET but may work?
        Dim strPathString As String
        Dim isOpen As Boolean
        Dim lngNumPages As Long
      
        
       isOpen = True
       
        ' open the PDF
        Set pdDoc = CreateObject("AcroExch.PDDoc")  '<<<<
        
        isOpen = pdDoc.open("D:\test.PDF")
      
            Set page = Nothing
            
            page = acroPD.AcquirePage(0)
            'may need Set page = acroPD.AcquirePage(0)
            
            pt = page.GetSize()
            
            Set rect = New Acrobat.AcroRect
            
            rect.Top = 0
            
            rect.Left = 0
            
            rect.Right = pt.x
            
            rect.bottom = pt.y

            Call page.CopyToClipboard(rect, 0, 0, 100)
            data = Clipboard.GetData()
            bmp = data.GetData(DataFormats.bitmap)
            bmp.Save ("D:\test.jpeg")
               
End Sub

Open in new window

0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 35136306
for a fully vb6 method of saving bitmap... http://www.bigresource.com/Tracker/Track-vb-lnXdBCddZl/

you need to use an picturebox control as an intermediate step.
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 35139124
Per this link:   http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/0623ed73-e68e-453a-999e-c1d98a90a2a2/

Dim doc As Acrobat.CAcroPDDoc
Dim page As Acrobat.CAcroPDPage
Dim pt As Acrobat.AcroPoint
Dim rect As Acrobat.AcroRect
Dim data As IDataObject
Dim bmp As Bitmap
              '***********************************

                'Test using forum code

                '***********************************

                doc = New Acrobat.AcroPDDocClass()
                page = Nothing
                doc.Open("C:\Documents and Settings\tk46261\My Documents\sickdays.pdf")
                page = doc.AcquirePage(0)
                pt = page.GetSize()
                rect = New Acrobat.AcroRect
                rect.Top = 0
                rect.Left = 0
                rect.right = pt.x
                rect.Bottom = pt.y

                page.CopyToClipboard(rect, 0, 0, 100)
                data = Clipboard.GetDataObject()
                bmp = data.GetData(DataFormats.Bitmap)
                bmp.Save("C:\Documents and Settings\tk46261\Desktop\Print Excel To JPG\test.jpeg")
 
0
 

Author Comment

by:KimberelyB
ID: 35140149
Thanks for your valuable comments.
But the problem I have is when i try to open a PDF document on the line.
isOpen = pdDoc.Open("D:\test.PDF")
I tried Option Explicit , but it didnt help.

I have Adobe Reader9.0 installed on the machine, do i need to have Adobe Professional? Please let me know.
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 50 total points
ID: 35142463
definitely need Acrobat Pro.    The free Acrobat Reader does not include any methods of opening PDF files directly within VB6. And no methods of manipulating PDF.  other than shell to PDFTK, a third party app.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question