Skip to end of metadata
Go to start of metadata

Declaration

Delphi

function AddBitmapFile(const FileName: WideString; Left: Double; Top: Double; Width: Double; Height: Double; PageNumber: Integer): Integer; stdcall;

ActiveX

HRESULT _stdcall AddBitmapFile([in] BSTR FileName, [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. The Left,Top,Width,Height are the PDF coordinates of the insertion.

Important:

Be sure to call LoadDoc before calling this function!

Arguments

 

FileNameThe filename of the Image, use file type Bitmap
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

Calculation of the PDF coordinates

The top/left has the value 0/0 and for the calculation you can use the following formula:

A4= 8.27 x 11.69 inch with 72points/inch = 595x842 points

1 point = 0.03527777778 centimeters

1 point = 0.01388888889 inch

Example: 5cm are 142 points (5cm / 0.03527777778 = 141,7323)

Samples

C# - AddBitmapFile
// Load your PDF
SignAPIv4.LoadDoc(@"c:\Temp\Mustermann.pdf");

// Select the Image and add it to the PDF
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
	FileName = ofd.FileName;
	int AddBitmapFileStatus = SignAPIv4.AddBitmapFile(FileName, 100, 100, 250, 200, 1);                
}
Delphi - AddBitmapFile
procedure TForm1.ButtonAddBMPFileClick(Sender: TObject);
var
    RetCode : Integer;
    msg : String;
begin
    OpenDialog1.Filter := 'Bitmap|*.bmp|All|*.*';

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

    RetCode := SignApi.AddBitmapFile(OpenDialog1.FileName,
                        strtofloat(EditAddBMPLeft.Text),
                        strtofloat(EditAddBMPTop.Text),
                        strtofloat(EditAddBMPWidth.Text),
                        strtofloat(EditAddBMPHeight.Text),
                        strtoint(EditAddBMPPageNumber.Text));

    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;

vb.Net - AddBitmapFile
Dim addPicStatus As Integer
addPicStatus = SignatureAPIv4.AddBitmapFile("TestImage.png", 100, 100, 250, 250, 1)

Select Case addPicStatus
	Case 0
		MessageBox.Show("Insertion error from Library")
	Case 1
		MessageBox.Show("Insertion sucessfull")
	Case 2
		MessageBox.Show("Exception while Loading File, wrong file format")
	Case 3
		MessageBox.Show("Bitmap from File is undefined or size of bitmap is 0/0")
	Case 4
		MessageBox.Show("The delivered HBITMAP is 0 or INVALID_HANDLE_VALUE")
	Case 5
		MessageBox.Show("Exception while inserting bitmap")
	Case 6
		MessageBox.Show("No document loaded, use LoadDoc")
	Case 7
		MessageBox.Show("The document is already signed.")
	Case 8
		MessageBox.Show("The Bitmap is too big for the pdf document.")
End Select

 

 

  • No labels