delete selected pages in sourcefile

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
gunnuy
Posts: 4
Joined: Thu Sep 06, 2018 10:51 am

delete selected pages in sourcefile

Post by gunnuy »

Hi,
I'd like to enable the user to have thumbnail viewer selected pages being deleted in the source file.
My approach ends here:

Code: Select all

Dim selectedImage As VintasoftImage() = Nothing
Dim selectedIndices As Integer() = .thumbnailViewer1.SelectedIndices.ToArray()
If _myCollection.Count > 0 Then
    selectedImage = New VintasoftImage(selectedIndices.Length - 1) {}
    For i As Integer = 0 To _myCollection.Count - 1
        selectedImage(i) = .thumbnailViewer1.Images(_myCollection(i))
        Dim image As VintasoftImage = selectedImage(i)
        image.Dispose() ' problem is here
    Next
End If

How do I write back those remaining pages to the source file?
A code sample would greatly be appreciated!

Thank you and Best
Regards
Guenther
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: delete selected pages in sourcefile

Post by Alex »

Hi Guenter,

Here is example that shows how to delete selected thumbnails in thumbnail viewer and save image in thumbnail viewer to a file. As filename can be used the name of new file or source file.

Code: Select all

Private Sub RemoveSelecedImagesAndSave(thumbnailViewer As ThumbnailViewer, filename As String)
    Dim indexes As Integer() = thumbnailViewer.SelectedIndices.ToArray()
    Dim removingImages As New List(Of VintasoftImage)
    For Each index As Integer In indexes
        removingImages.Add(thumbnailViewer.Images(index))
    Next
    thumbnailViewer.Images.RemoveRange(indexes)
    
    For Each image As VintasoftImage In removingImages
        image.Dispose()
    Next
    
    Dim encoder As EncoderBase = AvailableEncoders.CreateEncoder(filename)
    encoder.SaveAndSwitchSource = True
    thumbnailViewer.Images.SaveSync(filename, encoder)
End Sub
Best regards, Alexander
gunnuy
Posts: 4
Joined: Thu Sep 06, 2018 10:51 am

Re: delete selected pages in sourcefile

Post by gunnuy »

Hallo Alex,

works as intended, thanks a lot!!
Post Reply