COMPDF_LoadStreamAsWatermark

<< Click to Display Table of Contents >>

Navigation:  Tasks > Convert PDF into watermark >

COMPDF_LoadStreamAsWatermark

COMPDF_LoadStreamAsWatermark - this command was added to V5 to support loading a PDF from a stream to be used as watermark. Please note that the stream stays in memory until the viewer is cleared. You can pass an identifier number (2 bytes) to this command if you need more than a single PDF stream to be used as watermark.

 

This command must be used 1) to load a stream. Pass as pointer parameter an event stream structure. The high word of the integer parameter is the identifier. The result value is the count of loaded pages.

 

To convert a page from the PDF into a watermark object call this command again with the PTR parameter set to 0. The high word in the integer parameter

has be the indentifyer (the number used in step 1). The low word is the page number (0..$FFFF) of the page to be converted. The result value is either <=0 or the ID of the watermark object which can be used with COMPDF_ApplyWatermark.

 

The VCL wrapper provides this functions for step 1 and 2:  

 

function LoadPDFWatermarkFromStream( Stream: TStream; StreamID : Word ): Integer;

function LoadPDFWatermarkStreamGetPage( StreamID : Word; PageNo   : Word ): Integer;

 

Example:

 

procedure TForm1.AddaPDFfileaswatermark1Click(Sender: TObject);
var
    i, l, id : Integer;
    f : TFileStream;
begin
        OpenDialog1.Filter := 'PDF File (*.PDF)|*.PDF';
        OpenDialog1.Options := [ofFileMustExist];
 
        if OpenDialog1.Execute  then
        begin
           f :=  TFileStream.Create( OpenDialog1.FileName, fmOpenRead );
           try
              l := wpviewpdf1.LoadPDFWatermarkFromStream( f, 777 );
              if l>0 then
              begin
                 if l>wpviewpdf1.PageCount then 

                    l := wpviewpdf1.PageCount;
                 for I := 0 to  l-1 do
                 begin
                    id :=  wpviewpdf1.LoadPDFWatermarkStreamGetPage( 777, i );
                    if id>0 then
                    wpviewpdf1.CommandStrEx( 

                        COMPDF_ApplyWatermark, '1-1000', id );
                 end;
              end;
           finally
             f.Free;
           end;
        end;
end;