Solved

how do i convert pdf to jpeg using vb6.0

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

710 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