WPCubed GmbH
Wordprocessing and PDF components 

PDF manipulation in the backgroundPDFWorkBench

The PDFWorkBench is an window-less object to access the API of the PDF manipulation tool WPViewPDF PLUS.

 

The PDFWorkBench is an object which can be created using some functions which can be imported from the WPViewPDF DLL.

Introduction

This tool provides the developer with a powerful PDF manipulation tool which can be created and used very easy - in most developing languages under Windows OS. No window class has to be registered, no OCX has to be loaded, just import four easy to use functions.

 

A call to 'pdfWorkbenchCreate' creates a new workbench object. It will be freed by 'pdfWorkbenchFree'.

Using 'pdfWorkbenchLoad' a PDF file can be loaded or appended.

With 'pdfWorkbenchCommand' most commands used by WPViewPDF can be used with the work bench object. To do so, pass the command id as second parameter.

Definitions of the functions:

fktpdfWorkbenchCreate = function(
 licname, lickey: PWideChar; liccode: Cardinal ) : Pointer; stdcall;


fktpdfWorkbenchFree = function(
 workbench : Pointer ) :  Integer; stdcall;


fktpdfWorkbenchLoad = function(
 workbench : Pointer;
 Filename : PWideChar;
 Append, InMemory : Integer  ) : Integer; stdcall;


fktpdfWorkbenchCommand = function(
 workbench : Pointer;
 commandid : Integer;
 intpar : Integer;
 strpar : PWideChar;
 ptr : Pointer ) : Integer; stdcall;

The Delphi unit WPViewPDF3.pas loads this functions for convenient use:

wpview_pdfWorkbenchCreate := GetProcAddress(WPViewPDFDLLHandle,'pdfWorkbenchCreate');
wpview_pdfWorkbenchFree := GetProcAddress(WPViewPDFDLLHandle,'pdfWorkbenchFree');
wpview_pdfWorkbenchLoad := GetProcAddress(WPViewPDFDLLHandle,'pdfWorkbenchLoad');
wpview_pdfWorkbenchCommand := GetProcAddress(WPViewPDFDLLHandle,pdfWorkbenchCommand');

 

In this example the workbech is created "on the fly" to just read out the page count.

procedure TForm1.TestnonvisualPDFworkbench1Click(Sender: TObject);
var workbench : Pointer;
    s : String;
    function CommandGetString(
              id : Integer;
              strparam : String = '';
              intparam : Integer = 0 ) : String;
    var
      i: Integer;
    begin
      i := wpview_pdfWorkbenchCommand(workbench,id, intparam, PWideChar(strparam), nil);
      if i > 0 then
      begin
        SetLength(Result, i);
        wpview_pdfWorkbenchCommand(workbench, COMPDF_GetTextBufW, 0, nil, (@Result[1]) );
      end
      else
        Result := '';
    end;
begin
  if OpenDialog1.Execute then
  begin
   if not assigned(wpview_pdfWorkbenchCreate) then
     raise Exception.Create('wpview_pdfWorkbenchCreate is not available');
   workbench := wpview_pdfWorkbenchCreate(PWideChar(LicName), PWideChar(LicKey), LicCode );
   if not assigned(workbench) then
     raise Exception.Create('wpview_pdfWorkbenchCreate failed');
   try
     s := OpenDialog1.FileName;
     if wpview_pdfWorkbenchLoad( workbench, PWideChar(s), 0 , 0 )<0 then
         raise Exception.Create('wpview_pdfWorkbenchLoad failed');
     ShowMessage(
       Format('This PDF File has %d pages. DLL-Version = %s', [
        wpview_pdfWorkbenchCommand( workbench, COMPDF_GetPageCount, 0, nil, nil ),
        CommandGetString(COMPDF_GET_DLLVERSION)
         ] ) );
   finally
     wpview_pdfWorkbenchFree( workbench );
   end;
  end;
end;