The following code generated error as "System.OutOfMemoryException'" for version 6.0.0. The error was solved by 6.1.0 and 6.2.0. However, if run the code the second time (e.g. on the same page, click button that run the code again), the error generated.
The file the code run against is attached.
Tip for creating error:
1. make copy of the attached. 2. run the code (click a button that run the code). 3. delete generated pdf. 4. re_name the copied. 4. click the button again at in the same session.
Private Sub ResetPageNumber_Pack()
'Move old page number
Dim contentEditor As New Aspose.Pdf.Facades.PdfContentEditor()
Try
'bind input PDF file
contentEditor.BindPdf(outPutFile)
'make sure the regular expression strategy is being used
contentEditor.ReplaceTextStrategy.IsRegularExpressionUsed = True
'specify that you want to replace all the matching string
'by default only the first string will be replaced
contentEditor.ReplaceTextStrategy.ReplaceScope = Aspose.Pdf.Facades.ReplaceTextStrategy.Scope.REPLACE_ALL
'replace any string like 5467-3986-7 with new string
contentEditor.ReplaceText("[0-9.]*[A-Z.]*[a-z.]*[ ]*Page [0-9]+ of [0-9]+", String.Empty)
'save output PDF file
contentEditor.Save(outPutFile)
contentEditor.Close()
contentEditor = Nothing
'Write new page number
'open document
Dim pdfDocument As New Aspose.Pdf.Document(outPutFile)
'create page number stamp
Dim pageNumberStamp As New PageNumberStamp()
'whether the stamp is background
pageNumberStamp.Background = False
pageNumberStamp.Format = "Page # of " & pdfDocument.Pages.Count
pageNumberStamp.BottomMargin = 10
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center
pageNumberStamp.StartingNumber = 1
pageNumberStamp.TextState.FontSize = 9.0F
For i As Integer = 1 To pdfDocument.Pages.Count Step 1
'pageNumberStamp.Format = "Page " & i & " of " & pdfDocument.Pages.Count
pdfDocument.Pages(i).AddStamp(pageNumberStamp)
Next
'save output document
pdfDocument.Save(outPutFile)
pdfDocument = Nothing
Catch
Throw
End Try
End Sub