Solved

how do i convert pdf to jpeg using vb6.0

Posted on 2011-03-14
5
3,162 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…

756 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