Ver Mensaje Individual
  #24  
Antiguo 08-08-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
shoulder,

Cita:
Empezado por shoulder
...El ejemplo concreto es visualizar el PDF nada mas anulando todas las barras...


Te comento:

1- Para evitar los problema mencionados en tu caso particular en el Msg #19 opte por una solución alternativa : Sumatra PDF.

Cita:
What is Sumatra PDF?

Sumatra PDF is a free PDF, eBook (ePub, Mobi), XPS, DjVu, CHM, Comic Book (CBZ and CBR) reader for Windows.


Sumatra PDF is powerful, small, portable and starts up very fast.


Simplicity of the user interface has a high priority
.
2- Sumatra PDF permite parametrizar las opciones de visualización y funcionamiento de la aplicación, por medio de los archivos de configuración sumatrapdfrestrict.ini y SumatraPDF-settings.txt.

3- Sumatra PDF puede ser instalado de forma convencional o ser usado en su versión portable, para el código del ejemplo se utilizo la opción portable.

4- Sumatra PDF puede ser utilizado como un plugin dentro de un componente contenedor (TPanel, TForm), por medio de la opción: -plugin

5- Sumatra PDF es muy rápido, en pruebas realizadas en local un documento PDF de 857 páginas se cargo completamente en 2 segundos.

Revisa este código
Código Delphi [-]
  unit Unit1;
  
  interface
  
  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, Menus, ShellAPI, ExtCtrls, TlHelp32;
  
  type
    TForm1 = class(TForm)
      Panel1: TPanel;
      Button1: TButton;
      Button2: TButton;
      procedure Button1Click(Sender: TObject);
      procedure Button2Click(Sender: TObject);
      procedure FormCreate(Sender: TObject);
      procedure FormClose(Sender: TObject; var Action: TCloseAction);
    private
      { Private declarations }
    public
      { Public declarations }
    end;
  
  const
    TitleViewer : String = 'Viewer of Documents PDF';
  
  var
    Form1: TForm1;
    ProcessID : THandle;
  
  implementation
  
  {$R *.dfm}
  
  // Ejecuta un Proceso Externo
  function ShellExecuteApp(const CmdLine : String) : THandle;
  var
     PI : PROCESS_INFORMATION;
     SI : STARTUPINFO;
     RP : LongBool;
  
  begin;
  
     ZeroMemory(@PI, SizeOf(PI));
     ZeroMemory(@SI, SizeOf(SI));
  
     SI.cb := SizeOf(SI);
  
     RP := CreateProcess(nil, PChar(CmdLine), nil, nil, False,
                         NORMAL_PRIORITY_CLASS, nil, nil, SI, PI);
  
     WaitForSingleObject(PI.hProcess, 150);
  
     if Integer(RP) <> 0 then
     begin
        CloseHandle(PI.hThread);
        CloseHandle(PI.hProcess);
        Result := PI.dwProcessID;
     end
     else
        Result := 0;
  
  end;
  
  // Finaliza un Proceso por su ProcessID
  function TerminateProcessByID(ProcessID: Cardinal): Boolean;
  var
     Process : THandle;
  
  begin
  
     Process := OpenProcess(PROCESS_TERMINATE,False,ProcessID);
  
     if Process > 0 then
     try
        Result := TerminateProcess(Process,0);
     finally
        CloseHandle(Process);
     end
     else
        Result := False;
  
  end;
  
  // Inicialización de ProcessID
  procedure TForm1.FormCreate(Sender: TObject);
  begin
     ProcessID := 0;
  end;
  
  // Visualiza un Documento PDF en un TPanel con SumatraPDF
  procedure TForm1.Button1Click(Sender: TObject);
  var
     CmdLine : String;
     openDialog : TOpenDialog;
     Msg : String;
  
  begin
  
     if (ProcessID = 0) then
     begin
  
        openDialog := TOpenDialog.Create(self);
        openDialog.InitialDir := GetCurrentDir;
        openDialog.Options := [ofFileMustExist];
        openDialog.Filter := 'PDF files|*.pdf';
        openDialog.FilterIndex := 1;
  
        if openDialog.Execute then
        begin
  
           CmdLine := ExtractFilePath(Application.ExeName) + 'SumatraPDF.exe'
                      + ' -plugin '
                      + IntToStr(Panel1.Handle)
                      + ' '
                      + '"' + openDialog.FileName + '"';
  
           ProcessID := ShellExecuteApp(CmdLine);
  
           if ProcessID = 0 then
           begin
              Msg := 'Error de Inicialización de View PDF';
              MessageBox(Handle, PChar(Msg), PChar('Error'), MB_OK + MB_ICONERROR);
           end
           else
              Caption := TitleViewer + ' : ' + ExtractFileName(openDialog.FileName);
  
        end
        else
        begin
           Msg := 'No Se Selecciono Ningún Archivo PDF a Visualizar';
           MessageBox(Handle, PChar(Msg), PChar('Information'), MB_OK + MB_ICONINFORMATION);
        end;
  
     end
     else
     begin
        Msg := 'Existe un Documento Activo en el View PDF';
        MessageBox(Handle, PChar(Msg), PChar('Information'), MB_OK + MB_ICONINFORMATION);
     end;
  
  end;
  
  // Finaliza Visualización un Documento PDF en un TPanel con SumatraPDF
  procedure TForm1.Button2Click(Sender: TObject);
  begin
     if (ProcessID > 0) then
     begin
        TerminateProcessByID(ProcessID);
        ProcessID := 0;
        Caption := TitleViewer;
     end;
  end;
  
  // Cierra y Libera los Recursos del Formmulario
  procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  begin
     Action := caFree;
  end;
  
  end.
El código anterior en Delphi 7 bajo Windows 7 Professional x32, permite visualizar documentos PDF por medio de Sumatra PDF en modo plugin dentro de un componente TPanel, con las opciones de salvar e imprimir documentos PDF inhabilitadas, como se muestra en la siguiente imagen:



El código del ejemplo con la versión portable de Sumatra PDF, esta disponible en: Viewer of Documents PDF with SumatraPDF.rar

Revisa la siguiente información:
Nota: Te sugiero usar la versión portable de Sumatra PDF, la cual podrás distribuir con tu aplicación junto con los archivos de configuración (Puedes usar los del ejemplo) ó hacer la instalación (Copia) en el Servidor de dicha versión, todo depende del número de usuarios que utilicen tu aplicación.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 08-08-2014 a las 10:05:10.
Responder Con Cita