GetImages.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing

'' 这个示例加载一个PDF(我们使用Wetlands示例生成的文档)
'' 并从中提取所有图像。然后它将这些图像打印到新的 PDF 中,
'' 每页居中一个。
Public Class GetImages
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim tf = New TextFormat() With {.Font = StandardFonts.Times, .FontSize = 12}
        Using fs = New FileStream(Path.Combine("Resources", "PDFs", "Wetlands.pdf"), FileMode.Open, FileAccess.Read)
            Dim docSrc = New GcPdfDocument()
            '' 加载包含一些图像的现有 PDF:
            docSrc.Load(fs)
            '' 此调用从加载的 PDF 中提取有关图像的信息,
            '' 请注意,对于大文件,可能需要一段时间才能完成:
            Dim imageInfos = docSrc.GetImages()

            Dim doc = New GcPdfDocument()
            Dim textPt = New PointF(72, 72)
            Dim imageRc = New RectangleF(72, 72 * 2, doc.PageSize.Width - 72 * 2, doc.PageSize.Height - 72 * 3)

            For Each imageInfo In imageInfos
                '' 同一张图片可能出现在多个位置,
                '' imageInfo 包括页面索引和页面位置;
                '' 为了简单起见,我们只在这里打印页码:
                Dim sb = New StringBuilder()
                imageInfo.Locations.ForEach(Function(il_) sb.Append((il_.Page.Index + 1).ToString() + ", "))
                Dim g = doc.NewPage().Graphics
                g.DrawString($"This image appears on page(s) {sb.ToString().TrimEnd(" "c, ","c)} of the original PDF:", tf, New PointF(72, 72))
                g.DrawImage(imageInfo.Image, imageRc, Nothing, ImageAlign.ScaleImage)
            Next
            '' 完毕:
            doc.Save(stream)
            Return doc.Pages.Count
        End Using
    End Function
End Class