Thank you for replying. I would like to share the file, but unfortunately these are high school transcripts and subject to FERPA. Any modification made to the files to hide sensitive data also corrects the file’s error.
Out of 100 or so files, 4 created this error. I will tinker with these to see if they have anything in common. The code where where the error occurs is pdfDocument1.Save(pdfFS) – again, this code runs fine for almost all of the files. Finding the reason the Save method exception is looping seems key. Sorry i can’t share the file.
Public Shared Function BookmarkPDF(ByRef doc1Bytes As Byte(), ByVal newBookmarkDesc As String, Optional recordID As Integer = 0, Optional ByRef w As webAppUser = Nothing, Optional nomName As String = “”) As Byte()
' adds an initial bookmark to a document's outline collection
Dim pdfFS As Stream = New MemoryStream
Dim pdflicense As Aspose.Pdf.License = New Aspose.Pdf.License()
pdflicense.SetLicense(cfg.localPath & "\App_Data\Aspose.Pdf.lic")
pdflicense.Embedded = True
'a new PDF object is needed.
Dim pdfDocument1 As Aspose.Pdf.Document = Nothing
Dim fs1 As Stream = New MemoryStream(doc1Bytes)
' save the bytes to the new PDF
pdfDocument1 = New Aspose.Pdf.Document(fs1)
' set the bookmark to page 1; clear any existing artifactual bookmarks as they can cause errors if more are added later
Dim bookmarkAt As Integer = 1
If newBookmarkDesc <> "" Then
' create a bookmark object
Dim pdfOutline As OutlineItemCollection = New OutlineItemCollection(pdfDocument1.Outlines)
pdfOutline.Title = newBookmarkDesc
pdfOutline.Italic = True
pdfOutline.Bold = True
pdfOutline.Action = New Aspose.Pdf.Annotations.GoToAction(pdfDocument1.Pages(bookmarkAt)) ' Set the destination page number
' Add a bookmark in the document's outline collection.
'save the document to a memory stream
Catch ex As Exception
' some files are corrupted/encrypted and cannot be merged. insert a blank page with text.
sendMissingPageAlert(newBookmarkDesc, ex.Message, recordID, w, nomName)
pdfDocument1 = createMissingPage(newBookmarkDesc)
If Not IsNothing(pdfDocument1) Then pdfDocument1.Dispose()
' tidy up and return the stream as a byte array