ImageEn, unit iexPdfiumCore |
|
TPdfObjectList.AddImage
Declaration
function AddImage(X, Y, Width, Height: Single; Bitmap: TBitmap; MaintainAR: Boolean = True; Rotation: Double = 0; DoInsert: Boolean = False; InsertIndex: Integer = 0): TPdfObject; overload;
function AddImage(X, Y, Width, Height: Single; Bitmap: TIEBitmap; MaintainAR: Boolean = True; Rotation: Double = 0; DoInsert: Boolean = False; InsertIndex: Integer = 0): TPdfObject; overload;
function AddImage(X, Y, Width, Height: Single; const Filename: string; MaintainAR: Boolean = True; Rotation: Double = 0; DoInsert: Boolean = False; InsertIndex: Integer = 0): TPdfObject; overload;
Description
Add an image object to the current page at the specified position (in terms of PDF points).
If DoInsert is enabled, the object will be inserted at the specified InsertIndex (i.e. its z-position is set, where 0 is the object closest to the page, and Count-1 is the front-most object).
Note:
◼Rotation occurs at (x,y). So for rotation of 180 deg. for example, x,y will be the top-right of the image
◼You must call
ApplyChanges before saving to apply object changes to the document
PDF Page Points
Objects on a PDF page are specified in points that originate at the bottom-left, i.e. when X,Y = (0,0). The top-left of the page is specified by (
PageWidth,
PageHeight).
To convert PDF points to screen values, use
PageToScr.
var
bmp: TIEBitmap;
begin
if dlgOpenImage.Execute() then
begin
bmp := TIEBitmap.Create();
try
if bmp.LoadFromFile( dlgOpenImage.Filename ) = False then
EXIT;
ImageEnView1.PdfViewer.Objects.AddImage( 100, 800, 200, 200, bmp );
finally
bmp.Free();
end;
end;
end;
// Which is the same as...
begin
if dlgOpenImage.Execute() then
ImageEnView1.PdfViewer.Objects.AddImage( 100, 800, 200, 200, dlgOpenImage.Filename );
end;
// Add an image wherever user clicks on a PDF page (position image so click position is at the top-left)
procedure TfrmMain.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
clickPos: TDPoint;
bmp: TIEBitmap;
begin
clickPos := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
bmp := TIEBitmap.Create( 'D:\pix100x100.bmp' );
ImageEnView1.PdfViewer.Objects.AddImage( clickPos.X, clickPos.Y - bmp.Height, bmp.Width, bmp.Height, bmp );
bmp.Free();
end;
// Same as above but scale a large image to output at max of 200x200 (with aspect ratio maintained)
procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
Display_Width = 200;
Display_Height = 200;
var
clickPos: TDPoint;
bmp: TIEBitmap;
sz: TPoint;
begin
clickPos := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
bmp := TIEBitmap.Create( 'D:\LargeImage.jpg' );
// What size is it when scaled?
sz := GetImageSizeWithinArea( bmp.Width, bmp.Height, Display_Width, Display_Height );
ImageEnView1.PdfViewer.Objects.AddImage( clickPos.X, clickPos.Y - sz.Y, Display_Width, Display_Height, bmp );
bmp.Free();
end;
// Add a watermark image to a PDF page
procedure TfrmMain.AddWatermarkImage(const WatermarkFilename: string);
begin
// Load image into page at full size of the page
obj := ImageEnView1.PdfViewer.Objects.AddImage( 0, 0, ImageEnView1.PdfViewer.PageWidth, ImageEnView1.PdfViewer.PageHeight, WatermarkFilename, False );
// Send image behind all other images (it will be the last object)
ImageEnView1.PdfViewer.Objects.ArrangeObject( obj, 0 );
end;
// Insert an image at index 0, i.e. close to the background (below all other objects)
ImageEnView1.PdfViewer.Objects.AddImage( 100, 100, 200, 200, 'C:\Image.jpg', Maintain_AR, RotationDeg, True, 0 );
See Also
◼SetImage
◼GetImage
◼GetImageRaw