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)
Try
' 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
pdfDocument1.Outlines.Delete()
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.
pdfDocument1.Outlines().Add(pdfOutline)
End If
'save the document to a memory stream
pdfDocument1.Save(pdfFS)
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)
pdfDocument1.Save(pdfFS)
Finally
If Not IsNothing(pdfDocument1) Then pdfDocument1.Dispose()
End Try
' tidy up and return the stream as a byte array
fs1.Dispose()
Return common.convertStreamToByteArray(pdfFS)
End Function