// 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 );
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.SaveToFile( '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.SaveToFile( 'D:\PDFTest\Object_' + i.ToString + '.png' ); bmp.Free; end;
// Set the text of all text objects in page ImageEnView1.LockPaint(); for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do if objType = ptText then ImageEnView1.PdfViewer.Objects[i].Text := 'Text Object ' + i.ToString; ImageEnView1.UnlockPaint();
// Replace all the images in the page bmp := TIEBitmap.Create(); try bmp.LoadFromFile( '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;
// Remove the highlighted object from the PDF page ImageEnView1.PdfViewer.Objects.RemoveObject( ImageEnView1.PdfViewer.Objects.HighlightedIndex );
// Delete the item clicked on procedure TfrmMain.ImageEnView1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var idx: Integer; pt: TDPoint; begin pt := ImageEnView1.PdfViewer.ScrToPage( X, Y, True ); idx := ImageEnView1.PdfViewer.Objects.FindObjectAt( pt ); if idx > -1 then if MessageDlg( format( 'Delete object %d?', [ idx + 1 ]), mtConfirmation, [ mbYes,mbNo ], 0 ) = mrYes then ImageEnView1.PdfViewer.Objects.RemoveObject( idx ); end;