Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a PDF doc in Delphi 5

Status
Not open for further replies.

Delphiwhat

Programmer
Apr 1, 2003
74
0
0
EU
Hi folks
Anybody any ideas on how to open a PDF doc inside a window in my application. Or alternatively invoke adobe viewer or something.

I have a pdf that I want to view when a button is clicked in my application

cheers

j
 
You can use ShellExecute. It will open any file with the default program for that file type.

May be another way, but that's what we use.

Leslie


 
If you wan to view the PDF file inside your application, you can use a TOleContainer if you want.

--------------------------------------
What You See Is What You Get
 
You can use pdf.ocx.
If you have acrobat reader installed, you can find it in ProgramFiles\Adobe\Acrobatx\Rreader\Activex

Install in (Components\installactivex\ ...)

Open a new project, drag the component on the form

procedure TForm1.Button1Click(Sender: TObject);
begin
pdf1.src := ...\mypdf.pdf';
end;

This is THE BEST SOLUTION

Giovanni Caramia
 
I am using Delphi 6, and using the same approach to open PDF files: e.g.

NewPDFapp := TPdf.Create(Self);
NewPDFapp.src := pdfFile;

But when I run the application, although it starts to open Acrobat reader, it doesn't show the file.

I have a feeling this is a known problem. Is so, can anyone tell me a known solution!

 
I have tried out ShellExecute, Aaron, and although it works with some file types, it does not work with PDF files on my PC. I hasten to add I can open PDF files via Windows Explorer just by double clicking on the file, so it seems to me there must be something in the way Delphi and Acrobat reader interact.

Peter
 
This is a bit of a strange workaround, and there may well be a better way, but the following works for me:
Code:
  ShellExecute(0, 'Open', PChar('C:\...\prices.pdf'), PChar(''), PChar(''), SW_Hide);
  ShellExecute(0, 'Open', PChar('C:\...\prices.pdf'), PChar(''), PChar(''), SW_Hide);
or
Code:
  ShellExecute(0, 'Open', PChar('C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe'), PChar(''), PChar(''), SW_Hide);
  ShellExecute(0, 'Open', PChar('C:\...\prices.pdf'), PChar(''), PChar(''), SW_Hide);
The first ShellExecute call seems to open Acrobat and the second opens the pdf file itself?!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
i dont know why you want it hidden but change the SW_Hide to SW_Show then the one line is enough.

Code:
ShellExecute(0, 'Open', PChar('C:\prices.pdf'), PChar(''), PChar(''), SW_Show);

Aaron Taylor
John Mutch Electronics
 
I have tried repeating the ShellExecute without success, and I have tried it with SW_SHOW (and SW_SHOWMAXIMIZED and SW_SHOWNORMAL), but again without success. I have tried testing for errors with code like this:

if ShellExecute(0, NIL, PChar('c:\temp\test.pdf'), PChar(''), PChar(''), SW_SHOW) <= 32 then
showmessage('Error')
else
Showmessage('OK');

It returns 'OK', but still no file is shown. When you run the code, you can see Acrobat Reader opening, but then it disappears and the file never appears.

Peter
 
replace NIL by 'open' in the shellexecute and it will work

--------------------------------------
What You See Is What You Get
 
I read somewhere that you can pass a Null value. Anyway, I have now tried with 'open' and the problem persists: i.e. it does not work!!!

Peter
 
Doh!
Eureka!
I have just upgraded my Acrobat Reader from version 5 to version 6 and it works like a dream.
Thanks folks.
 
If you want open .pdf file in your window you can use WebBrowser component too:

Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  webbrowser1.Navigate('c:\..\MyPDFFile.pdf');
end;

Giovanni Caramia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top