WPViewPDF in MDI Style application

Questions about WPViewPDF - the new PDF view and print component
wpsupport
Site Admin
Posts: 7383
Joined: Fri Oct 24, 2003 4:06 pm
Contact:

WPViewPDF in MDI Style application

Postby wpsupport » Fri Jan 09, 2015 9:05 am

If you have a WPViewPDF control on a child unit the recommended way is to load the WPViewPDF engine from the main form, i.e. with this code:

Code: Select all

{$I PDFLicense.INC}

// please add "WPViewPDF3" to uses clause
procedure TViewMain.FormCreate(Sender: TObject);
var viewerdll : String;
begin
  {$IFDEF WIN64}
  viewerdll := ExtractFilePath( Application.ExeName ) + WPViewPDF_DLLName64;
  {$ELSE}
  viewerdll := ExtractFilePath( Application.ExeName ) + WPViewPDF_DLLName;
  {$ENDIF}

  if not WPViewPDFLoadDLL( viewerdll, true) then
  begin
    ShowMessage('PDF Viewing is not available');
    SelectPDFFile.Enabled := false;
  end;
end;


The childform with the viewer can then be created with a few lines of code:

Code: Select all

procedure TViewMain.SelectPDFFileClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  with TPDFView.Create(Self) do
  try
      // Not here, that would be to late - the control would have already tried the default path
      // WPViewPDF1.DLLName := path + 'wPDFViewPlus03.dll';

      // Set the license keys
      WPViewPDF1.ViewerStart( '', WPViewPDF_LicName, WPViewPDF_LicKey, WPViewPDF_LicCode );

      // Load
      WPViewPDF1.LoadFromFile(  OpenDialog1.FileName );

      // Show form, non modal
      Show;
  except
      Free;
  end;
end;


Note: Assigning a different name to WPViewPDF1.DLLName can be problematic, if the DLL was already loaded automatically.

Return to “WPViewPDF (VCL/OCX)”



Who is online

Users browsing this forum: No registered users and 1 guest