Solved

how do i convert pdf to jpeg using vb6.0

Posted on 2011-03-14
5
3,290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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