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