PDFiumVCL Docs

AddJpegImage method

Ten wpis API zachowuje identyfikatory, sygnatury, bloki kodu i terminy PDF w oryginalnej postaci.
Component: TPdf  ·  Unit: PDFium
Add JPEG image to the current PDF page using the specified coordinates.

Syntax

function AddJpegImage(JpegImage: TStream; X, Y, Width, Height: Double): Boolean;

JpegImageTStream. A stream containing raw JPEG-compressed data. The stream position should be at the start of the JPEG data when this method is called.

Return Value

Returns True if the JPEG data was successfully decoded and embedded on the page. Returns False if the stream does not contain valid JPEG data or if the embedding operation fails.

Description

AddJpegImage embeds a JPEG image supplied as a raw byte stream onto the current PDF page. Because the JPEG data is passed directly without re-encoding, image quality is preserved exactly as stored in the source stream. This makes the method well-suited for high-volume document generation where decoding and re-compressing images would introduce unnecessary quality loss or CPU overhead.

The JpegImage stream must contain a complete, valid JPEG file starting from the SOI marker. The stream's current position should be at the beginning of the JPEG data before calling this method. Any TStream descendant is accepted — TFileStream, TMemoryStream, database blob streams, and so on.

The X and Y parameters specify the lower-left corner of the placement rectangle in PDF user units (origin at page lower-left, Y increases upward). Width and Height set the rendered size on the page; the JPEG is scaled to fit regardless of its pixel dimensions.

The method returns True on success. If the stream does not contain valid JPEG data, it returns False without raising an exception, so callers should check the return value when working with data of uncertain origin.

Example

var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create('C:\Images\photo.jpg', fmOpenRead or fmShareDenyNone);
  try
    Pdf1.NewPage(595, 842);
    if not Pdf1.AddJpegImage(Stream, 72, 400, 300, 225) then
      ShowMessage('Failed to embed JPEG image.');
  finally
    Stream.Free;
  end;
end;

See Also

AddImage, AddPicture