Solved

how do i convert pdf to jpeg using vb6.0

Posted on 2011-03-14
5
2,976 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now