Free Support Forum - aspose.com

ArgumentOutOfRangeException while putting pagenumbers

Hi


We have a random exception that occures while trying to put stamps on an existing PDF. The output is stored as a new file. The PDF is rather large (over 1000 pages), an example is attached.
We tested the application on multiple machines and it seems that the exception occures on some of them more often than on others.

Specifications:
Aspose.Pdf 7.1.0.0
Visual Studio 2010
.NET Framework 3.5
C#

StackTrace:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.RemoveAt(Int32 index)
at ..( )
at ..(Int32 , )
at ..(Int32 , , , [] , Double , Double , Double , Double )
at Aspose.Pdf.Text.TextFragmentState.set_BackgroundColor(Color value)
at Aspose.Pdf.Text.TextBuilder.(TextFragment , Int32 , Boolean )
at Aspose.Pdf.TextStamp.Put(Page page)
at Aspose.Pdf.PageNumberStamp.Put(Page page)
at Aspose.Pdf.Page.AddStamp(Stamp stamp)
at PD.Band2.Core.Band2Operation.GenerateNewPageNumbersAndHideOldOnes(String pdfFile) in C:\Projects\PD\Band2\Main\PD.Band2.Core.Main\Band2Operation.cs:line 191
at PD.Band2.Core.Band2Operation.GeneratePDF(String legislaturSession, Rat rat, Language lang) in C:\Projects\PD\Band2\Main\PD.Band2.Core.Main\Band2Operation.cs:line 73

C#-Code (Occurence of problem highlighted):
private String GenerateNewPageNumbersAndHideOldOnes(String pdfFile)
{
log.Debug(“Generate pagenumbers over the document”);

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(pdfFile);
String outputPdfFile = pdfFile + “_Output.pdf”;

FormattedText formattedText = new FormattedText("#", Color.Black, Color.White,
Aspose.Pdf.Facades.FontStyle.Helvetica,
EncodingType.Winansi,
false, 10.0f, 14);
PageNumberStamp pageNumberStamp = new PageNumberStamp(formattedText);
pageNumberStamp.StartingNumber = 1;

FormattedText whiteBackgroundToHidePageNumber = new FormattedText(" ", Color.White, Color.White,
Aspose.Pdf.Facades.FontStyle.Helvetica,
EncodingType.Winansi, true, 14);
TextStamp textStamp = new TextStamp(whiteBackgroundToHidePageNumber);

for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
//add stamps to particular page
pdfDocument.Pages[i].AddStamp(textStamp);
pdfDocument.Pages[i].AddStamp(pageNumberStamp);
}

pdfDocument.Save(outputPdfFile);

log.Debug(“Finished generating pagenumbers over the document”);

return outputPdfFile;
}

Hi Matthias,


Thanks for contacting support.

I
have tested the scenario using Aspose.Pdf for .NET 7.9.0 over Windows 7(X64) where I have used Visual Studio 2010 and have set the target platform of my application as .NET Framework 3.5 and I am unable to notice any issue. The resultant PDF is properly being generated. Can you please try using the latest release version and in case the problem still persists, please feel free to contact.

We are sorry for this inconvenience.<o:p></o:p>

Hi codewarior is not online. Last active: 05-01-2013, 2:34 PMNayyer


Thanks for your fast reply!

As said, the problem doesn’t occur always and it seems to be depending on what machine the application is running. We have computers which are always able to generate the pagenumbers and others where the problem occures every second try.
Unfortunately, our subscription ran out by version 7.1.0 and it would be quiet an amount to invest, to still be unsure if the problem in our scenario would be solved or not.
We can’t test the trial version of 7.9.0, because it only allows four pages to be processed. And to reproduce the case, we would need to process over all the pages.

Hi Matthias,


The version of Aspose.Pdf for .NET that you have been using is quite old and till the release of v7.9.0, we have made many changes/improvements in our product. For the sake of testing, you may request a 30 days temporary license of product and try using Aspose.Pdf for .NET 7.9.0. When you are certain that problem does not occur anymore, you may consider upgrading your subscription.

However in the problem still persists, please share some sample application so that we can test the scenario at our end. We are sorry for this inconvenience.