Create Parent Bookmark in Large file

Hi Aspose Team,
We have following scenario in our system.
When we merging several pdf files, for each file we are creating a parent bookmark to distinguish these files later in pdf reader. But sometimes when pdf file with bookmarks is big (about 200 MB) and in pdf there are about 2000 pages, we are getting error message when trying to create a parent bookmark.

Error message: Tor mscorlib set_Capacity Exception of type ‘System.OutOfMemoryException’ was thrown. [OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.]
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
at ​ . ​ (Byte[] , Int32 , Int32 )
at ..( ​ , , Boolean , Int64& )
at ..​ ( ​ , )
at ​ .( ​ , , Boolean , Int64& )
at ​ .​ ( ​ , )
at ..( ​ , , Boolean , Int64& )
at ..​ ( ​ , )
at ​ .( ​ , , Boolean , Int64& )
at ​ .​ ( ​ , )
at ​ .( , Int32 )
at ​ .( ​ , Boolean )
at ​ .( ​ , Boolean )
at ​ . ​ ( ​ , ​ )
at ​ . ​ ()
at ​ . ​ (Stream )
at ​ . ​ (Stream )
at Aspose.Pdf.Document.Save(Stream output)
at Aspose.Pdf.Document.Save(String outputFileName)

We are using following code for parent bookmark creation:
Dim pOriginalFile As String = “Original.pdf”
Dim vBookmarkedFileName As String = “test.pdf”
Using vBookmarkedDoc As Aspose.Pdf.Document = New Aspose.Pdf.Document(pOriginalFile)

        Dim vRootBookmark As OutlineCollection = vBookmarkedDoc.Outlines
        Dim vNewRootBookmark As OutlineItemCollection = New OutlineItemCollection(vRootBookmark)
        vNewRootBookmark.Title = pOriginalFile
        vNewRootBookmark.Bold = True
        vNewRootBookmark.Destination = New FitHExplicitDestination(vBookmarkedDoc.Pages(1), 792)
        For Each vBookmark As OutlineItemCollection In vRootBookmark
            vNewRootBookmark.Add(vBookmark)
        Next

        vBookmarkedDoc.Outlines.Delete()
        vBookmarkedDoc.Outlines.Add(vNewRootBookmark)

        vBookmarkedDoc.Save(vBookmarkedFileName)
        vBookmarkedDoc.FreeMemory()
        If vBookmarkedDoc IsNot Nothing Then vBookmarkedDoc.Dispose()

        If File.Exists(vBookmarkedFileName) Then
            If File.Exists(pFilePath) Then
                File.Delete(pFilePath)
            End If
        End If
    End Using

Unfortunately we cannot attach file due confidentiality.

Best regards,
Dmitrij

@dmitrij.skaliov

Thank you for contacting support.

Would you please upload the file to Google Drive, Dropbox etc. and share the link with me via Private Message by clicking on my username and then sending a message. We will try to reproduce and investigate the scenario in our environment, to help you out.

@dmitrij.skaliov

Thank you for sharing requested data.

We have tried to execute your code with shared PDF document and the process consumes around 400MB memory without any exception. Would you please ensure using Aspose.PDF for .NET 19.4 and then share your kind feedback with us.