Example: Read page count

<< Click to Display Table of Contents >>

Navigation:  PDFWorkbench >

Example: Read page count

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, nilnil ),

        CommandGetString(COMPDF_GET_DLLVERSION)

         ] )

        );

   finally

     wpview_pdfWorkbenchFree( workbench );

   end;

  end;

end;