We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF to TIF Conversion- Multiple Threads- Arithmetic operation resulted in an overflow

I have a .NET application that uses Aspose libraries to convert PDF files to TIF files, and it uses Parallel.Foreach to perform these conversions simultaneously in multiple threads. In each thread, I create a new Resolution object, new TIffSettings object, and new TiffDevice object:

[code]

private TiffDevice getTiffConverter()

{

Resolution resolution = new Resolution(300);

var tiffSettings = new TiffSettings()

{

Compression = CompressionType.LZW,

Depth = ColorDepth.Format8bpp,

Shape = ShapeType.None,

SkipBlankPages = false

};

return new TiffDevice(resolution, tiffSettings);

}

[end code]

A new Pdf.Document object is created in each thread and TiffDevice.Process is called, where fileFullName and destinationFileFullName are strings:

[code]

using (var pdfToConvert = new Document(fileFullName))

{

var tiffConverter = getTiffConverter();

tiffConverter.Process(pdfToConvert, destinationFileFullName);

}

[end code]

When I run this with only 1 thread, it works fine, but if I run this in 10 simultaneous threads, then about 10% of the files will encounter the following exception:

[exception]

Message: Arithmetic operation resulted in an overflow.

Target Site: Int32 ToInt32()

Stack Trace: at System.IntPtr.ToInt32()

at ****.Get8BppImage(Bitmap )

at ****.***(Bitmap , PixelFormat )

at ****.**(Bitmap , Int32 , Int32 )

at ****.AddImage(Bitmap )

at Aspose.Pdf.Devices.TiffDevice.Process(Document document, Int32 fromPage, Int32 toPage, Stream output)

at Aspose.Pdf.Devices.DocumentDevice.Process(Document document, Stream output)

at Aspose.Pdf.Devices.DocumentDevice.Process(Document document, String outputFileName)

...

[end exception]

So the exception is happening underneath Aspose code, and I've also determined that PDF files where the exception occurs once can convert succesfully in repeated trials, so it doesn't seem to be related to specific PDF files. And even though it's around 10% of the files and 10 threads, the errors have come from any of the threads, not just one particular thread out of 10. I'm using Aspose.Pdf.dll version 10.5.0.0. Is this a bug? Is there anything I can do to work around it while still using multiple threads?

Hi Christopher,


Thanks for using our API’s.

Can you please share some sample project, so that we can test the conversion in our environment. We are sorry for this inconvenience.

I wrote a sample project that seems to more or less reproduce the issue. The errors occur with the same frequency, and in almost the same stack trace, but the message and type of exception are different. The error became an OutOfMemoryException, but I monitored my memory while running the application, and I never had less than 10GB of available memory at any point while it was running. It's possible this error could have the same sort of root cause as the other error I saw.

You'll need a "C:\Temp\Pdf" folder with at least 100 PDF files in it, and a "C:\Temp\Tif" folder for it to write files into. And I'm registering the Aspose license with a license file in the "C:\" folder.

In the full application code, when I tried the 4 bpp color depth or the Default color depth instead of the 8 bpp color depth, I wasn't getting any exceptions. Although when I try them on my sample project, I do get intermittent exceptions.

One difference between my full app code that I didn't try building into this sample that could conceivably be relevant to producing a different exception, in the full app, I'm using "Interlocked.Increment(ref fileCopyCount)" within the parallel loop to count some statistics for the files.

Hi Christopher,


Thanks for sharing the resource files.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-39029 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.

i have a related issue, when i run this on my debug project it works fine and convert the pdf to multiple tiff images but when i try to deploy the project don’t work and return the same error Arithmetic operation resulted in an overflow error this is the code I’m using to convert pdf to tiff images



TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.LZW;
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format8bpp;
Resolution rsl = new Resolution(300);

using (Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(filePath))
{
if (conversionSetting.IsDynamicPDF)
pdfDoc.Form.Type = Aspose.Pdf.Forms.FormType.Standard;
//create tiff device
Aspose.Pdf.Devices.TiffDevice tiffPdfDevice = new Aspose.Pdf.Devices.TiffDevice(rsl, tiffSettings);
//convert to TIFF image
for (int i = 0; i < pdfDoc.Pages.Count; i++)
{
string fileDestinationPath = GetDestinationPath(filePath, destinationDirectory, i);
try
{
using (FileStream outputStream = new FileStream(fileDestinationPath, FileMode.Create))
{
//Save as TIFF
tiffPdfDevice.Process(pdfDoc, i + 1, i + 1, outputStream);
images.Add(fileDestinationPath);
}
}
catch (Exception)
{
pdfDoc.FreeMemory();

foreach (var fileToDelete in images)
{
if (File.Exists(fileToDelete))
File.Delete(fileToDelete);
}
throw;
}
}

pdfDoc.FreeMemory();
}

Hi Javier,


Thanks for contacting support.

As per my understanding from your above description, the problem is appearing on particular system (where deployment is being made). Can you please share some details regarding deployment environment and and also please share if the issue is occurring for any specific PDF file or its appearing for all the documents. We are sorry for this inconvenience.
We are facing same issue related Arithmatic operation resulted in Overflow.

But observed that for same pdf, aspose image conversion works fine if ran in Visual studio unit test environment. But when deployed in IIS, image conversion throws Arithmatic operation resulted in Overflow exception.

We are using Aspose pdf 10.7.0

Looking in documentation, we found TiffDevice takes the implementation of IIndexBitmapConvertor. Are there multiple implementations available? Is there a possibility to try out different implementations here.



chetan9:
We are facing same issue related Arithmatic operation resulted in Overflow.

But observed that for same pdf, aspose image conversion works fine if ran in Visual studio unit test environment. But when deployed in IIS, image conversion throws Arithmatic operation resulted in Overflow exception.

We are using Aspose pdf 10.7.0

Looking in documentation, we found TiffDevice takes the implementation of IIndexBitmapConvertor. Are there multiple implementations available? Is there a possibility to try out different implementations here.
Hi Chetan,

Thanks for contacting support.

Can you please share your input PDF file, so that we can try replicating the issue in our environment. Now concerning to your query regarding different implementation techniques, I am in coordination with product team and as soon as we have some further updates, we will let you know.

We are sorry for this inconvenience.

Hi Nayyer,


Thank you for your reply. Unfortunately, due to some NDAs we can not share the PDF documents. But this problem is not with just one particular pdf, it is happening for all the PDFs (Specifically scanned PDFs not the text PDFs).


Regards,
Chetan

chetan9:
Hi Nayyer,

Thank you for your reply. Unfortunately, due to some NDAs we can not share the PDF documents. But this problem is not with just one particular pdf, it is happening for all the PDFs (Specifically scanned PDFs not the text PDFs).
Hi Chetan,

Thanks for sharing the updates.

The performance related issues are mainly PDF related, therefore we requested you to please share the input file. Furthermore, you can create a separate thread and mark it as private so that the contents shared in that thread will only be accessible to Aspose staff.

Nevertheless, the artifacts shared by customers are only used for testing purposes and once a particular issue is resolved, they are removed from our system.

Hi Nayyer,


Just one investigation point we got, wanted to clarify.
Is there two different dll for x86 and x64 in case Asponse PDF .NET dll.




Hi Chetan,


Thanks for your inquriy. No, we have a single Aspose.Pdf for .NET DLL for both x86 and x64 platforms, but different DLLs are available for different .NET Frameworks.

Best Regards,

We observed that error mentioned in this thread “Arithmatic Operation resulted in an Overflow” is happening in case we are using Aspose.Pdf.dll with version 10.7.0 in 64 bit mode. If we use it in 32bit mode, same code works for same pdf.


We tried upgrading to Aspose.Pdf.dll version 17.1.0 (We have aspose total license so upgrade is not problem from that side), problem went away. Even in 32bit or 64 bit the Aspose.Pdf.dll version 17.1.0 works perfectly fine. So may be 10.7.0 dll was an issue.

Hi Chetan,


Thanks for your feedback. It is good to know that your issue has been resolved with latest version of Aspose.Pdf for .NET. Please note we maintain a single code base, all fixes and improvements are made in latest version of Aspose.Pdf for .NET. So it is recommended to use latest version of Aspose.Pdf.

Please feel free to contact us for any further assistance.

Best Regards,