ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Iterate all the objects of a PDF page (PDFium)
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

xequte

38222 Posts

Posted - Oct 27 2023 :  02:11:21  Show Profile  Reply

// Output details of all objects of the current PDF page to a memo
var
  i: Integer;
  s: string;
  r: TRect;
  objType: TPdfObjectType;
  bmp: TIEBitmap;
  fontName: String;
  fontSize, strokeWidth: Single;
  fontWeight, italicAngle: Integer;
  strokeColor, fillColor, FontColor: TRGBA;
  pointArray: TIEDPointArray;
begin
  Memo1.Lines.Clear();
  for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
  begin
    Memo1.Lines.Add( 'OBJECT ' + i.ToString );

    // Type
    s := '';
    objType := ImageEnView1.PdfViewer.Objects.Items[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.Items[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.Items[i].Text );

      ImageEnView1.PdfViewer.Objects.Items[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.Items[i].StrokeColor;
      strokeWidth := ImageEnView1.PdfViewer.Objects.Items[i].StrokeWidth;
      fillColor := ImageEnView1.PdfViewer.Objects.Items[i].FillColor;

      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 ]));

      pointArray := ImageEnView1.PdfViewer.Objects.Items[i].GetPath();
      Memo1.Lines.Add( '  Point Count: ' + Length( pointArray ).ToString );
    end
    else
    // Image properties
    if objType = ptImage then
    begin
      bmp := TIEBitmap.Create();
      if ImageEnView1.PdfViewer.Objects.Items[i].GetImage( bmp ) then
        Memo1.Lines.Add( format( '  Image Size: %d x %d', [ bmp.Width, bmp.height ]));
      // ImageEnMView1.AppendImage( bmp );
      bmp.Free;
    end;
  end;
end;


Nigel
Xequte Software
www.imageen.com
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: