ImageEn, unit iexPdfiumCore

TPdfObject


Declaration

TPdfObject = class(TObject)


Description

Provides access to an object of the PDF page.



General Properties and Methods

Public Property  ObjectType
Public Method  GetImage
Public Method  GetImageRaw
Public Method  SetImage
Public Property  Text


Position Properties and Methods

Public Property  Bounds
Public Property  Matrix
Public Property  Width
Public Property  Height
Public Property  Rotation
Public Method  Scale
Public Method  TransformEx
Public Method  Translate
Public Property  X
Public Property  Y


Style Properties and Methods

Public Property  FillColor
Public Method  GetPath
Public Method  GetTextFont
Public Property  LineCap
Public Property  LineJoin
Public Property  PathFillMode
Public Property  PathStrokeWidth
Public Property  StrokeColor
Public Property  StrokeWidth


Demo

Demo  Demos\Other\PDFPageObjects\PDFPageObjects.dpr


Examples

// Output details of all page objects to a memo
var
  i, p, ptCount: Integer;
  s: string;
  r: TRect;
  bmp: TIEBitmap;
  objType: TPdfObjectType;
  fontName: String;
  fontSize, strokeWidth: Single;
  fillMode: TPdfFillMode;
  fontWeight, italicAngle: Integer;
  isStroked: Boolean;
  strokeColor, fillColor, FontColor: TRGBA;
  pointArray: TIEDPointArray;
  pts: string;
begin
  Memo1.Lines.BeginUpdate();
  Memo1.Lines.Clear();
  Memo1.Lines.Add( format( 'Page %d: %d x %d', [ ImageEnView1.PdfViewer.PageIndex, Round( ImageEnView1.PdfViewer.CurrentPage.Width ), Round( ImageEnView1.PdfViewer.CurrentPage.Height )] ));
  for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
  begin
    Memo1.Lines.Add( 'OBJECT ' + i.ToString );

    // Type
    s := '';
    objType := ImageEnView1.PdfViewer.Objects[i].ObjectType;
    case objType of
      ptUnknown  : s := 'Unknown';
      ptText     : s := 'Text';
      ptPath     : s := 'Path';
      ptImage    : s := 'Image';
      ptShading  : s := 'Shading';
      ptForm     : s := 'Form';
    end;
    Memo1.Lines.Add( '  Type: ' + s );

    // Bounds
    r := ImageEnView1.PdfViewer.Objects[i].Bounds;
    Memo1.Lines.Add( Format( '  Bounds: %d,%d,%d,%d', [ r.Left, r.Top, r.Right, r.Bottom ]));

    // Text properties
    if objType = ptText then
    begin
      Memo1.Lines.Add( '  Text: ' + ImageEnView1.PdfViewer.Objects[i].Text );

      ImageEnView1.PdfViewer.Objects[i].GetTextFont( fontName, fontSize, fontColor, fontWeight, italicAngle );
      Memo1.Lines.Add( '  Font Name: ' + fontName );
      Memo1.Lines.Add( '  Font Size: ' + fontSize.ToString );
      Memo1.Lines.Add( Format( '  Font Color: %d,%d,%d/%d', [ fontColor.r, fontColor.g, fontColor.b, fontColor.a ]));
      Memo1.Lines.Add( '  Font Weight: ' + fontWeight.ToString );
      Memo1.Lines.Add( '  Italic Angle: ' + italicAngle.ToString );
    end
    else
    // Path properties
    if objType = ptPath then
    begin
      strokeColor := ImageEnView1.PdfViewer.Objects[i].StrokeColor;
      strokeWidth := ImageEnView1.PdfViewer.Objects[i].PathStrokeWidth;
      fillColor   := ImageEnView1.PdfViewer.Objects[i].FillColor;
      fillMode    := ImageEnView1.PdfViewer.Objects[i].FillMode;

      Memo1.Lines.Add( Format( '  Stroke Color: %d,%d,%d/%d', [ strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ]));
      Memo1.Lines.Add( '  Stroke Width: ' + strokeWidth.ToString );
      Memo1.Lines.Add( Format( '  Fill Color: %d,%d,%d/%d', [ fillColor.r, fillColor.g, fillColor.b, fillColor.a ]));
      Memo1.Lines.Add( Format( '  Fill Mode: %d', [ ord( fillMode )]));

      ImageEnView1.PdfViewer.Objects[i].GetPath( pointArray, ptCount );
      Memo1.Lines.Add( '  Point Count: ' + ptCount.ToString );

      pts := '';
      for p := 0 to Length( pointArray ) - 1 do
      begin
        if pointArray[p].x = IE_PointArray_ClosingBreak then
          pts := pts + format( ',CLOSE', [ Round( pointArray[p].X ), Round( pointArray[p]. Y )])
        else
        if pointArray[p].Y = IE_PointArray_Break then
          pts := pts + format( ',BREAK', [ Round( pointArray[p].X ), Round( pointArray[p]. Y )])
        else
          pts := pts + format( ',(%d,%d)', [ Round( pointArray[p].X ), Round( pointArray[p]. Y )]);
      end;
      if pts <> '' then
        Delete(pts, 1, 1 );
      Memo1.Lines.Add( '  Points: ' + pts );
    end
    else
    // Image properties
    if objType = ptImage then
    begin
      bmp := TIEBitmap.Create();
      if ImageEnView1.PdfViewer.Objects[i].GetImage( bmp ) then
      begin
        Memo1.Lines.Add( format( '  Image Size: %d x %d', [ bmp.Width, bmp.height ]));
        // Save?  bmp.Write( 'D:\_PDF\Image_'+i.ToString+ '.png');
        // Show in MView?  ImageEnMView1.AppendImage( bmp );
      end;
      bmp.Free();
    end;
  end;
  Memo1.Lines.EndUpdate();
end;


// Save all images in the page to file
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
  if ImageEnView1.PdfViewer.Objects[i].ObjectType = ptImage then
  begin
    bmp := TIEBitmap.Create();
    if ImageEnView1.PdfViewer.Objects[i].GetImage( bmp ) then
      bmp.Write( 'D:\PDFTest\Object_' + i.ToString + '.png' );
    bmp.Free;
  end;


// Set the text of all text objects in page
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
  if objType = ptText then
    ImageEnView1.PdfViewer.Objects[i].Text := 'Text Object ' + i.ToString;
ImageEnView1.Invalidate();


// Replace all the images in the page
bmp := TIEBitmap.Create();
try
  bmp.Read( 'D:\MyLogo.jpg' );
  for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
    if ImageEnView1.PdfViewer.Objects[i].ObjectType = ptImage then
    begin
      if ImageEnView1.PdfViewer.Objects[i].SetImage( bmp ) = False then
        BREAK;
    end;
finally
  bmp.Free;
  ImageEnView1.PdfViewer.ReloadPage();
end;