How to: Extract Images from a Document
- 2 minutes to read
Important
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.
This example illustrates the use of the PdfDocumentProcessor.GetImages method for obtaining document bitmaps in code by using PDF Document API.
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports DevExpress.Pdf
' ...
Shared Sub Main(ByVal args() As String)
Dim processor As New PdfDocumentProcessor()
processor.LoadDocument("..\\..\\Demo.pdf")
Dim xCount As Integer = 8
Dim yCount As Integer = 2
Dim cardWidth As Double = 150.5 ' Measured in points (equals 2.09 inches).
Dim cardHeight As Double = 442 ' Measured in points (equals 6.138 inches).
Dim xMargin As Double = 122 ' Measured in points (equals 1.694 inches).
Dim yMargin As Double = 77 ' Measured in points (equals 1.069 inches).
Dim yCoord As Double = yMargin
Dim y As Integer = 0
Do While y < yCount
Dim xCoord As Double = xMargin
Dim x As Integer = 0
Do While x < xCount
Dim area As New PdfDocumentArea(1, New PdfRectangle(xCoord, yCoord, xCoord + cardWidth, yCoord + cardHeight))
Dim bitmaps As IList(Of Bitmap) = processor.GetImages(area)
If bitmaps.Count <> 0 Then
bitmaps(0).Save(String.Format("{0}_{1}.bmp", x, y))
bitmaps(0).Dispose()
End If
Console.WriteLine(bitmaps.Count.ToString())
x += 1
xCoord += cardWidth
Loop
y += 1
yCoord += cardHeight
Loop
End Sub
See Also