Load PDF

<< Click to Display Table of Contents >>

Navigation:  Commands >

Load PDF

When loading an encrypted PDF file (which uses a non-empty password) a message box to enter the password will pop up.

 

To prevent this You can use

 

COMPDF_SetLoadPassword  = 120

 

Sets master load password. This can also be done in the NeedPassword event!

 

COMPDF_AddPassword  = 122

 

Adds a password to the list of passwords to be used.

 

COMPDF_ClearPasswords  = 121

 

Clear the complete list of passwords.

 

 

When using the VCL it is better to use the high level load methods.

 

COMPDF_FastLoad = 99

 

Loads but do not display a PDF file. The name is passed as StrParam. The result value is the count of pages.

 

COMPDF_UpdatePages  = 107

 

Force the update of the bookmark and scroller. This is not required for the load methods below.

 

 

COMPDF_Clear = 100

 

Removes all loaded PDF data and closes any streams opened by the component.

 

COMPDF_Load = 101

 

Load a PDF file. If IntPar=1 the file will be copied to memory - this makes it possible to delete, move or overwrite the original file.

The result value is the count of pages.

 

COMPDF_Append = 102

 

Appends a PDF file. If IntPar=1 the file will be copied to memory - this makes it possible to delete, move or overwrite the original file.

The result value is the count of pages.

 

COMPDF_AppendHGlobal = 103

COMPDF_LoadEHGlobal  = 95

 

Load or append the PDF data from a HGLOBAL memory handle.

 

COMPDF_AppendIStream = 104

COMPDF_LoadIStream  = 96

 

LOad or append PDF from a COM stream. IntParam is an interface pointer.

 

COMPDF_AppendIStreamKeepOpen = 108

 

Works like COMPDF_AppendIStream but keep the stream open!

 

COMPDF_AppendEStream = 105 (create copy)

COMPDF_LoadEStream = 97 (create copy)

COMPDF_AppendEPStream  = 106 (keep stream open)

COMPDF_LoadEPStream     = 98 (keep stream open)

 

Load or Append PDF from an event stream. Event streams are implemented as a structure with 3 function pointers.

The first 2 create a copy of the data, the second 2 keep the stream open.

 

The WPViewPDF VCL uses this streams internally.

 

Definition:

 

TEventStreamFkt = packed 

record

    OnStreamRead: function(data: Pointer; buffer: Pointer; len: Integer)

      : Integer;

    stdcall;

    OnStreamWrite: function(data: Pointer; buffer: Pointer; len: Integer)

      : Integer;

    stdcall;

    OnStreamSeek: function(data: Pointer; Offset: Integer; Origin: Integer)

      : Integer;

    stdcall;

    Stream: TStream;

end;

 

function ReadEvent(data: Pointer; buffer: Pointer; len: Integer): Integer;

  stdcall;

begin

  Result := PEventStreamFkt(data).Stream.Read(PAnsiChar(buffer)^, len);

end;

 

function WriteEvent(data: Pointer; buffer: Pointer; len: Integer): Integer;

  stdcall;

begin

  Result := PEventStreamFkt(data).Stream.Write(PAnsiChar(buffer)^, len);

end;

 

function SeekEvent(data: Pointer; Offset: Integer; Origin: Integer): Integer;

  stdcall;

begin

  Result := PEventStreamFkt(data).Stream.Seek(Offset, Origin);

end;

 

Usage:

 

function TWPViewPDF.LoadFromStream(Stream: TStream; WithClear: Boolean = false): Boolean;

var

  events: TEventStreamFkt;

begin

  events.Stream := Stream;

  events.OnStreamRead := Addr(ReadEvent);

  events.OnStreamWrite := Addr(WriteEvent);

  events.OnStreamSeek := Addr(SeekEvent);

  try

    if WithClear then

    begin

      if FEngineVersion < 3000 then

      begin

        CommandEx(COMPDF_Clear, 0);

        Result := CommandEx(COMPDF_AppendEStream, Cardinal(@events)) = 0;

      end

      else

        Result := CommandEx(COMPDF_LoadEStream, Cardinal(@events)) = 0

    end

    else

      Result := CommandEx(COMPDF_AppendEStream, Cardinal(@events)) = 0;

  except

    Result := false;

  end;

end;