RemoveSquareImages.vb
''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports GrapeCity.Documents.Pdf

Public Class RemoveSquareImages
    Public Function CreatePDF(ByVal stream As Stream) As Integer
        Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "SlidePages.pdf"))
            Dim doc = New GcPdfDocument()
            doc.Load(fs)
            ' Get the list of images in the document:
            Dim imageInfos = doc.GetImages()
            ' Remove non-square images from the list:
            For i = imageInfos.Count - 1 To 0 Step -1
                If imageInfos(i).Image.Width <> imageInfos(i).Image.Height Then
                    imageInfos.RemoveAt(i)
                End If
            Next
            ' Remove images left in the list from the PDF:
            doc.RemoveImages(imageInfos)
            '' Done:
            doc.Save(stream)
            Return doc.Pages.Count
        End Using
    End Function
End Class