Solved

Open an existing PDF document from VB.net using OLE automation

Posted on 2004-09-28
14
7,911 Views
Last Modified: 2008-01-09
Hello,

I want to open an existing PDF file using OLE automation.

I have built a project which allows the user to open Word and Excel templates.

I am using the following code to open Word/Excel:

Dim wordApp as Word.Application
Dim wordDoc as Word.Document
wordApp = New Word.Application
wordApp.Visible = True
wordDoc = wordApp.Documents.Add

I would ideally like the reference needed as well as the code to access the pdf file.

Thanks

Gareth
0
Comment
Question by:GarethWham
  • 5
  • 4
  • 2
  • +3
14 Comments
 

Expert Comment

by:Daniel_Iankov
ID: 12168299
I don't think that you can actually open pdf file with VB, because the pdf format is property of Adobe. I am sure that you could export data in this format (I' ve done it), there are no generic methods to edit pdf file in VB.

Try searching for an open source component that edits files - may find one out there.

If you are trying to open the pdf file Fron your app with Acrobat Reader then use

ShellExecute(hwnd, "Open", "filename.pdf", 0&, 0&, SW_SHOW)  
0
 

Expert Comment

by:Daniel_Iankov
ID: 12168377
Sorry - SW_SHOW is not defined in VB, old c++ :)
try 5 istead
0
 

Expert Comment

by:Maharaj80
ID: 12168385
The way suggested by Daniel would intern would actually depend on Adobe Acrobat reader being installed over there on the machine and also its not Win32 automation .
Gareth can you please give more exact specs abt why you need a word document to open a PDF file. Infact, if you need to extract text or image from pdf there is free source code available on the next.
The source code for one of the tools is available at
http://www.verypdf.com/pdf2htm/index.html

it inturn depends on XPDF library obtained at following url

 http://www.foolabs.com/xpdf/download.html

Best of luck!



0
 

Author Comment

by:GarethWham
ID: 12168584
I just need to open a pdf file from vb.net. I may be able to use shell. Thanks for your comments, will let you know how I get on
0
 

Author Comment

by:GarethWham
ID: 12168809
I have managed to use the shell function to open adobe reader which is:

Shell ("C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe")

Now, does anyone know the switch to open a pdf file.

For example, when you shell a word template the switch is \t (then the path of the template)

I want to put in a switch to open an existing file any ideas?

Many thanks
0
 

Expert Comment

by:Daniel_Iankov
ID: 12168889
Actually there is no need to start the acrord.exe .
After you are using the  shell routine just use:

shell ("start " +<file paht and name>,,,,,);
The string filename.pdf must include
 The default app for the file is autostarted
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12168928
plz visit the following link
http://www.code101.com/Code101/DisplayArticle.aspx?cid=69
i hope it'll be of any help
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:GarethWham
ID: 12169128
Daniel,

That doesn't seem to work. I am using the following code.

("start""C:\Documents and Settings\J Smith\Publications\FileName.pdf")

Is there a reference I need to use?

0
 

Expert Comment

by:Daniel_Iankov
ID: 12169210
Well you've got to add + between the two strings:)
0
 

Expert Comment

by:Daniel_Iankov
ID: 12169228
and put  space char after start the string should be:

"start C:\Documents and Settings\J Smith\Publications\FileName.pdf" or

"start " + "C:\Documents and Settings\J Smith\Publications\FileName.pdf"
0
 
LVL 5

Accepted Solution

by:
Jojo1771 earned 500 total points
ID: 12169264
Here is How I open pdfs for my projects. This will try version 6 or 5 then just try to open file based off what its associated with..

'function to determine adobe version and use that version. 6 or 5
    Function Readeropen(ByVal FiletoOpen As String)
        Try
            Shell("C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe " & FiletoOpen, AppWinStyle.MaximizedFocus)
        Catch ex As Exception
            Try
                Shell("C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe " & FiletoOpen, AppWinStyle.MaximizedFocus)
            Catch ex2 As Exception
                Try
                    Start(FiletoOpen)
                Catch ex3 As Exception
                    MsgBox("Adobe Acrobat Reader v5.0 or higher can not be found.", MsgBoxStyle.Exclamation, "Reader missing.")
                End Try
            End Try
        End Try

    End Function
0
 

Author Comment

by:GarethWham
ID: 12169713
Cheers all,

Sorted by using the following:

Shell ("Full File Path to Adobe Executable File & Full File Path to PDF File")

0
 
LVL 5

Expert Comment

by:Jojo1771
ID: 12171784
system.diagonistics or what ever it is called.
needs to be included to do

start(FiletoOpen)
This will open the file with the associated app.

Just incase the shell one dosn't always work.

Thanks and GL
0
 
LVL 2

Expert Comment

by:pdrau
ID: 12411083
If you own Acrobat 6.0, you can reference the acrobat.tlb Acrobat Type Library.  I don't think it is available with the free 6.0 reader though.

This is part of my code that I use to merge .PDF files.

        Dim AcroApp As Acrobat.CAcroApp
        Dim PDDoc As Acrobat.CAcroPDDoc
        Dim InsertPDDoc As Acrobat.CAcroPDDoc
        Dim iNumberOfPagesToInsert As Integer, iLastPage As Integer
        Dim goRound As Integer, strOutput As String, strTest As String

        On Error GoTo ErrorHandler
        AcroApp = CreateObject("AcroExch.App")
        PDDoc = CreateObject("AcroExch.PDDoc")
        InsertPDDoc = CreateObject("AcroExch.PDDoc")

Hope this helps.
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

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

12 Experts available now in Live!

Get 1:1 Help Now