ImageEn, unit iexPdfiumCore |
|
TPdfObjectList.AddImage
Declaration
function AddImage(X, Y, Width, Height: Single; Bitmap: TBitmap; MaintainAR: Boolean = True; Rotation: Double = 0): TPdfObject; overload;
function AddImage(X, Y, Width, Height: Single; Bitmap: TIEBitmap; MaintainAR: Boolean = True; Rotation: Double = 0): TPdfObject; overload;
function AddImage(X, Y, Width, Height: Single; const Filename: string; MaintainAR: Boolean = True; Rotation: Double = 0): TPdfObject; overload;
Description
Add an image object to the current page at the specified position (in terms of PDF points).
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;