Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opening PDFs with Adobe Reader

Posted on 2010-11-15
8
Medium Priority
?
2,034 Views
Last Modified: 2012-05-10
We are currently having issues with PDF files being called. Below is the code that executes a PDF file from within the program. However we have a client where they have two versions of Adobe installed. (Normal Adobe Reader – Free, and Adobe Acrobat Standard - paid for).
We have checked the file extensions associated with PDFs and its set to open with the free version. However, when we try and open the PDF from within our program it opens up with the paid for version, which they only have a couple of licences for.
Is there any way we can force the PDF to open in the free version of adobe acrobat?

function stExecProgram(flname : string) : Boolean;
var
  ShellInfo : TShellExecuteInfo;
  msg, holdflname : string;
  res : DWord;
begin
  holdflname := flname;
  if (holdflname[1] = '"') then
  begin
    holdflname := copy(holdflname, 2, Length(holdflname) - 2);
  end;
  if (not FileExists(holdflname)) then
  begin
    MessageDlg('Unable to find File: ' + holdflname, mtError, [mbOK], 0);
    result := False;
    exit;
  end
  else
  begin
    FillChar(ShellInfo, SizeOf(TShellExecuteInfo), 0);
    ShellInfo.cbSize := SizeOf(TShellExecuteInfo);
    ShellInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
    ShellInfo.Wnd := HWnd_Desktop;
    ShellInfo.lpFile := pchar(holdflname);
    ShellInfo.lpVerb := 'OPEN';
    ShellInfo.nShow := SW_NORMAL; //sw_ShowMaximized;
    result := ShellExecuteEx(@ShellInfo);
    if (not result) then
    begin
      res := GetLastError;
      case res of
        ERROR_FILE_NOT_FOUND : msg := 'The specified file was not found';
        ERROR_PATH_NOT_FOUND : msg := 'The specified path was not found';
        ERROR_DDE_FAIL         : msg := 'The DDE transaction failed';
        ERROR_NO_ASSOCIATION : msg := 'There is no application associated with the given filename extension';
        ERROR_ACCESS_DENIED     : msg := 'Access to Document of Application Denied';
        ERROR_DLL_NOT_FOUND     : msg := 'Application Extension (DLL) Not Found';
        ERROR_CANCELLED         : msg := 'Operation Cancelled by User';
        ERROR_NOT_ENOUGH_MEMORY : msg := 'Insufficient Memory to Execute Application';
        ERROR_SHARING_VIOLATION : msg := 'A sharing violation occurred';
      end;
      MessageDlg(msg, mtError, [mbOK], 0);
    end;
  end;
end;
0
Comment
Question by:futurelinksw
[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
8 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 34135332
You can try something like this:

ShellExecute(Handle,'open', 'C:\Program Files\Adobe\AcrReader.exe','c:\YourFile.pdf', nil, SW_SHOWNORMAL);
{Supply a fully qualified path name in ProgramName}
procedure ExecNewProcess(ProgramName : String);
var
  StartInfo  : TStartupInfo;
  ProcInfo   : TProcessInformation;
  CreateOK   : Boolean;
begin

  { fill with known state }
  FillChar(StartInfo,SizeOf(TStartupInfo),#0);
  FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
  StartInfo.cb := SizeOf(TStartupInfo);

  CreateOK := CreateProcess(PChar(ProgramName),nil, nil, nil,False,
              CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS, 
              nil, nil, StartInfo, ProcInfo);

  { check to see if successful }
  if CreateOK then
    //may or may not be needed. Usually wait for child processes
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 34135369
Please discard the last code snippet that I attached.

You only have to use this line:

ShellExecute(Handle,'open', 'C:\Program Files\Adobe\AcrReader.exe','c:\YourFile.pdf', nil, SW_SHOWNORMAL);

Please note:
"C:\Program Files\Adobe\AcrReader.exe" to be replaced with the path to the free version of adobe acrobat.

"c:\YourFile.pdf" this is your file that you want to open.


uses ShellApi;

function stExecProgram(PDFApp, flname : string) : Boolean;
begin
 ShellExecute(Handle,'open', PDFApp,flname, nil, SW_SHOWNORMAL);
end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 34135503
You can make your program to look up for the different Acrobat Reader Applications installed on the Clients' PC's and if more than to give and option to select which one the client wants to use to open the intended PDF file. Still figuring it out, will get back to you.

After trying the code, there is an update:

uses ShellApi;

function stExecProgram(PDFApp, flname : string) : Boolean;
begin
  ShellExecute(0,'open', PChar(PDFApp), PChar(flname), nil, SW_SHOWNORMAL);
end;

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 24

Accepted Solution

by:
jimyX earned 252 total points
ID: 34137434
Here is an example on how to detect the installed Adobe Acrobat PDF and let the client select which one to be used. You can add the ability of setting/changing a default selection or come up with suitable re-implementation to fit your requirements.

This is only to show an example still you can improve it.

BTW, seems it is not possible to install more than two versions of Acrobat in your system (at least the Adobe installer will not accept).

// Form 1

{
    Button1: TButton;
}

uses Registry;

procedure TForm1.Button1Click(Sender: TObject);
var
  Reg : TRegistry;
begin
  Reg:= TRegistry.Create;
  try
    Reg.RootKey:= HKEY_LOCAL_MACHINE;  // Root key (directory)
    Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\App paths\Acrobat.exe\', False);
    Form2.ListBox1.Items.Add(Reg.ReadString(''));
    Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\App paths\AcroRd32.exe\', False);
    Form2.ListBox1.Items.Add(Reg.ReadString(''));
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
  Form2.ShowModal;
end;


//Form 2

{
    ListBox1: TListBox;
    Label1:TLabel;
    Button1: TButton;
    Button2: TButton;
}

uses ShellApi;


procedure OpenPDF(PDFApp,PDFFile:string);
begin
  ShellExecute(0,'open',Pchar(PDFApp),Pchar(PDFFile),nil,SW_SHOWNORMAL);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  if ListBox1.ItemIndex < 0 then
    showmessage('Please select ....')
  else
    begin
      OpenPDF(ListBox1.Items[ListBox1.ItemIndex],'C:\ExExPDFfile.pdf'); 
      Close;
    end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  Close;
end;

Open in new window

Form2.JPG
0
 
LVL 1

Assisted Solution

by:DelRunner
DelRunner earned 248 total points
ID: 34211464
Why not show the pdf document within your application using the Acrobat PDF TypeLibrary that comes with the Free Acrobat Reader?
This is howto in Delphi6 which I'm using - still.

Go to Component in the menu, select Import ActiveX, in the list look for something like Adoe Acrobat and click Install. In the ActiveX tab you will now have a pdf component, the name depends a bit on what ver of Acrobat Reader you have installed.
All you have to do then is drop the component on a form, and the coding for opening the pdf file is:

  AcroPDF1.LoadFile(OpenDialog1.FileName);

Good luck
/DelRunner
0
 

Author Comment

by:futurelinksw
ID: 34247634
Thanks all for your suggestions - I will be meeting with the developers again soon to discuss the options.

Kind regards.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 34700456
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

661 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