''
'' 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 RemoveImageLocation
Public Function CreatePDF(ByVal stream As Stream) As Integer
Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "ImageTransparency.pdf"))
Dim doc = New GcPdfDocument()
doc.Load(fs)
' Get the list of images in the document:
Dim imageInfos = doc.GetImages()
' For each image with multiple locations, remove the leftmost location:
For Each ii In imageInfos
If ii.Locations.Count > 1 Then
Dim iLeft As Integer = -1
For i = 0 To ii.Locations.Count - 1
If iLeft = -1 OrElse ii.Locations(i).PageBounds.ToRect().Left < ii.Locations(iLeft).PageBounds.ToRect().Left Then
iLeft = i
End If
Next
' Remove the locations we want to keep:
For i = ii.Locations.Count - 1 To 0 Step -1
If i <> iLeft Then
ii.Locations.RemoveAt(i)
End If
Next
' Remove the locations that are left:
doc.RemoveImages({ii})
End If
Next
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Using
End Function
End Class