AddBitmapHandle

Declaration

Delphi

function TSignApi4Object.AddBitmapHandle(hBitmap: HBITMAP; Left, Top, Width, Height: Double; PageNumber: Integer):Integer; stdcall;

ActiveX

HRESULT _stdcall AddBitmapHandle([in] OLE_HANDLE hBitmap, [in] double Left, [in] double Top, [in] double Width, [in] double Height, [in] long PageNumber, [out, retval] long * RetVal );

Description

Use this function to insert a Bitmap into the PDF document from an HBITMAP. The Left,Top,Width,Height are the PDF coordinates of the insertion.

Important:

Be sure to call LoadDoc before calling this function!

Arguments


hBitmapThe HBITMAP to an image
Left

Position from the left side in PDF coordinates

TopPosition from the top side in PDF coordinates
WidthSize Width of Viewing area from the Image
HeightSize Height of the Viewing Area from Image
PageNumberPagenumber in the PDF document from 1..n


Return value

valuenamedescription
0

abError_BLSLIB                    

Insertion error from Library
1abOkInsertion sucessfull
2abError_LoadExceptionException while Loading File, wrong file format
3abError_BitmapErrorBitmap from File is undefined or size of bitmap is 0/0
4abError_HBITMAPInvalidThe delivered HBITMAP is 0 or INVALID_HANDLE_VALUE
5abError_BLSExceptionException while inserting bitmap
6abError_NoDocLoadedNo document loaded, use LoadDoc
7abError_DocIsSignedThe document is already signed.
8abError_BMPSizeTooBigThe Bitmap is too big for the pdf document

Samples

Delphi - AddBitmapHandle
procedure TForm1.ButtonAddBMPHandleClick(Sender: TObject);
var
    RetCode : Integer;
    bmp : TBitmap;
    msg : String;
begin
    OpenDialog1.Filter := 'Bitmap|*.bmp|All|*.*';

    if (not OpenDialog1.Execute()) then
        exit;

    bmp := TBitmap.Create;
    bmp.LoadFromFile(OpenDialog1.FileName);

    RetCode := SignApi.AddBitmapHandle(bmp.Handle,
                        strtofloat(EditAddBMPLeft.Text),
                        strtofloat(EditAddBMPTop.Text),
                        strtofloat(EditAddBMPWidth.Text),
                        strtofloat(EditAddBMPHeight.Text),
                        strtoint(EditAddBMPPageNumber.Text) );
    bmp.Free;

    case RetCode of
        0 : // abError_BLSLIB
            msg := 'Error from Library';
        1 : // abOk
            msg := 'Image inserted successfully';
        2 : // abError_LoadException
            msg := 'Exception when loading image';
        3 : // abError_BitmapError
            msg := 'Bitmap is NIL or Size=0/0';
        4 : // abError_HBITMAPInvalid
            msg := 'Bitmap handle is invalid';
        5 : // abError_BLSException
            msg := 'Exception in library';
        6 : // abError_NoDocLoaded
            msg := 'No document loaded';
        7 : // abError_DocIsSigned
            msg := 'Document is already signed - no image insertion possible';
        8 : // abError_BMPSizeTooBig
            msg := 'Image size too big';
        else
            msg := 'unknown error = ' + inttostr(RetCode);
    end;

    MessageBox(Handle, PChar(msg), 'AddBitmapFile', MB_OK or MB_ICONINFORMATION);
end;