Hi,
I’m using Aspose PDF 10.5.1.0
In the code below if you use it in parallel mode you get.
Exception on page 130
Parameter is not valid.
at System.Drawing.Bitmap…ctor(Int32 width, Int32 height, PixelFormat format)
at ?.…ctor(? , )
at ?..§(? , )
at ?.?…ctor( , §◄:bangbang: , ? )
at ?.§☼.Process( document, §◄:bangbang: page, ? device, ?& context)
at ?⌂↓.?♫.??¶(?& context)
at Aspose.Pdf.Devices.ImageDevice.??¶(Page )
at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)
at ConsoleApplication3.Program.ProcessPage(Int32 page) in d:\temp\ConsoleApplication3\Program.cs:line 21
Page number change each time you run it.
In linear mode no problems.
Reproduced on Windows 7 and 2013 Server R2.
Attached project + PDF file
static string m_file;
static void ProcessPage(int page)
{
try
{
using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(m_file))
{
using (System.IO.FileStream ms2 = System.IO.File.Create(string.Format(“out{0:000}.png”, page)))
{
Aspose.Pdf.Devices.PngDevice png = new Aspose.Pdf.Devices.PngDevice((int)(21f * 300f / 2.54f), (int)(29.7f * 300f / 2.54f), new Aspose.Pdf.Devices.Resolution(300));
png.Process(doc.Pages[page], ms2);
}
}
}
catch (Exception ex)
{
Console.WriteLine(“Exception on page {0}”, page);
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
throw ex;
}
}
static void Main(string[] args)
{
if (args.Length == 2)
{
new Aspose.Pdf.License().SetLicense(new System.IO.MemoryStream(Properties.Resources.Aspose_Total));
m_file = args[1];
DateTime start = DateTime.Now;
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(m_file);
int pageCount = doc.Pages.Count;
doc.Dispose();
if (args[0] == “l”)
{
for (int i = 0; i < pageCount; i++)
ProcessPage(i + 1);
}
else if (args[0]==“p”)
Parallel.For(1, pageCount + 1, ProcessPage);
Console.WriteLine((DateTime.Now - start).TotalSeconds);
}
else
Console.WriteLine(“test.exe [p|l] pdfFile”);
}