Back to Devexpress

PdfDocumentProcessor.GetImagesInfo(PdfDocumentArea) Method

officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-dot-getimagesinfo-x28-devexpress-dot-pdf-dot-pdfdocumentarea-x29.md

latest5.5 KB
Original Source

PdfDocumentProcessor.GetImagesInfo(PdfDocumentArea) Method

Retrieves images and their boundaries found within the specified document area.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public IList<PdfBitmapBox> GetImagesInfo(
    PdfDocumentArea area
)
vb
Public Function GetImagesInfo(
    area As PdfDocumentArea
) As IList(Of PdfBitmapBox)

Parameters

NameTypeDescription
areaPdfDocumentArea

A PdfDocumentArea object that represents a document area.

|

Returns

TypeDescription
IList<PdfBitmapBox>

A collection of PdfBitmapBox objects.

|

Remarks

The overloaded GetImagesInfo method uses the page coordinate system. See the following topic for more information: Coordinate Systems.

The following example uses the GetImagesInfo(PdfDocumentArea) method to obtain all images and their boundaries from the specified page and to draw a red rectangle around them.

csharp
using DevExpress.Drawing;
using DevExpress.Pdf;
using System.Collections.Generic;
using System.Drawing;
// ...
static void Main(string[] args) {

    using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
        processor.LoadDocument(@"..\\..\\Demo.pdf");
        // Specify the area from which the images are obtained.
        PdfDocumentArea area = new PdfDocumentArea(1,
            new PdfRectangle(0, 0, processor.Document.Pages[0].CropBox.Width,
                processor.Document.Pages[0].CropBox.Height));
        // Retrieve images and their boundaries.
        IList<PdfBitmapBox> bitmaps = processor.GetImagesInfo(area);
        // Draw a rectangle around boundaries of each image.
        for (int i = 0; i < bitmaps.Count; i++) {
            var r = bitmaps[i].Bounds;
            float rectFLeft = (float)r.Left;
            float rectFTop = (float)(processor.Document.Pages[0].CropBox.Height - r.Top);
            float rectFWidth = (float)r.Width;
            float rectFHeight = (float)r.Height;

            PdfGraphics graphics = processor.CreateGraphicsWorldSystem();
            using (var pen = new DXPen(Color.Red, 5))
                graphics.DrawRectangle(pen, new RectangleF(rectFLeft, rectFTop, rectFWidth, rectFHeight));
                graphics.AddToPageForeground(processor.Document.Pages[1]);
        }
        // Print the resulting document.
        DXBitmap bitmap = processor.CreateDXBitmap(1, 1000);
        PdfPrinterSettings pdfPrinterSettings = new PdfPrinterSettings();
        processor.Print(pdfPrinterSettings);
    }
}
vb
Imports DevExpress.Drawing
Imports DevExpress.Pdf
Imports System.Collections.Generic
Imports System.Drawing
' ...
Shared Sub Main(ByVal args() As String)
    Using processor As New PdfDocumentProcessor()
        processor.LoadDocument("..\\..\\Demo.pdf")
        ' Specify the area from which the images are obtained.
        Dim area As New PdfDocumentArea(1, New PdfRectangle(0, 0, processor.Document.Pages(0).CropBox.Width,
            processor.Document.Pages(0).CropBox.Height))
        ' Retrieve images and their boundaries.
        Dim bitmaps As IList(Of PdfBitmapBox) = processor.GetImagesInfo(area)
        ' Draw a rectangle around boundaries of each image.
        For i As Integer = 0 To bitmaps.Count - 1
            Dim r = bitmaps(i).Bounds
            Dim rectFLeft As Single = CSng(r.Left)
            Dim rectFTop As Single = CSng(processor.Document.Pages(0).CropBox.Height - r.Top)
            Dim rectFWidth As Single = CSng(r.Width)
            Dim rectFHeight As Single = CSng(r.Height)

            Dim graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
            Using pen = New DXPen(Color.Red, 5)
                graphics.DrawRectangle(pen, New RectangleF(rectFLeft, rectFTop, rectFWidth, rectFHeight))
            End Using
                graphics.AddToPageForeground(processor.Document.Pages(1))
        Next i
        ' Print the resulting document.
        Dim bitmap As DXBitmap = processor.CreateDXBitmap(1, 1000)
        Dim pdfPrinterSettings As New PdfPrinterSettings()
        processor.Print(pdfPrinterSettings)
    End Using
End Sub

See Also

How to: Extract Images from a Document with DevExpress PDF Document API

PdfDocumentProcessor Class

PdfDocumentProcessor Members

DevExpress.Pdf Namespace