Aspose.PDF Parameter is not valid on JPEGDevice

In my application, I have a document upload capability. Once the document reaches my web server, I convert it to an Aspose.PDF document from the original string. Next the app converts the pages one-by-one to bitmaps from which it looks for barcodes on the image. About half of the time on my production environment, the JPEGDevice throws the exception below: "Parameter is not valid."

This happens about half the time on my production environment. I've never seen it on any other environments.

Can you shed any light on why this exception is being thrown? Is the stream invalid or is the document page invalid? If the page, does that imply that the page and hence the parent document is corrrupted in some fashion?
I should have said, the documents where the exception is throw may upload and be read successfully during a subsequent trial or on our other environments. Likely it is not a problem with the specific documents.

I've included the stack trace from the exception below and a simplified version of my code.

Thanks.

Lance Safford

at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at ...ctor(? , )
at .?.(? , )
at .?..ctor( , ? )
at ..( , ? )
at .?.()
at Aspose.Pdf.Devices.ImageDevice.(Page )
at Aspose.Pdf.Devices.JpegDevice.Process(Page page, Stream output)

Aspose.Pdf.Document inputDoc = new Aspose.Pdf.Document(stream);

Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices. JpegDevice(new Aspose.Pdf.Devices.Resolution(int.Parse(ABS2FileLibRes.imageResolution)), int.Parse(ABS2FileLibRes.imageQuality));

bool barcodesFound = true;

foreach (Aspose.Pdf.Page pge in inputDoc.Pages)
{
using (MemoryStream imageStream = new MemoryStream())
{
//exception is thrown from the line below
jpegDevice.Process(pge, imageStream);
//
barcodeImage = new Bitmap(imageStream);
}
//do application stuff
}

Hello Lance,


Thanks for using our products.

I have tested the scenario where I have used one of my sample PDF documents and have made a slight change in the code snippet that you have shared (changed MemoryStream object to FileStream so that I can get the copy of resultant Image) and I am unable to notice any issue on Windows7 X64 while I have been using VisualStudio 2010 Ultimate. I have set the target platform of my application as .NET Framework 4.0 and I have tested on Windows application.

As you have been facing issue on production environment, can you please share some details regarding your production environment i.e. Operating System, OS Architecture, .NET Framework version, VisualStudio version etc. Also if possible, please share a sample application which can help us in replicating this issue in our environment. We are really sorry for this inconvenience.

PS, One suggestion, as you have saving the JpegDevice output in Bitmap object, you may consider closing the imageStream object once barcodeImage object is initialized.