Solved

Opening PDFs with Adobe Reader

Posted on 2010-11-15
8
1,936 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
8 Comments
 
LVL 24

Expert Comment

by:jimyX
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

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!

 
LVL 24

Accepted Solution

by:
jimyX earned 63 total points
Comment Utility
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 62 total points
Comment Utility
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
Comment Utility
Thanks all for your suggestions - I will be meeting with the developers again soon to discuss the options.

Kind regards.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now