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

Free Support Forum - aspose.com

pdfConverter not work well in multiple theads

hi, I have a lot of pdf need to conver to image. I use the pdfConverter.GetNextImage method in multiple theads, but the performance is more worse than single thead. why? not support?

Hi,


Thanks for using our products.

The conversion of PDF to Images depends upon the structure and complexity of source PDF file and due to the input PDF file which you are using, the conversion process might be taking longer duration. Can you please share the source PDF file so that we can test the scenario at our end. We are sorry for this inconvenience.

PS, Aspose.Pdf for .NET is supported in multi-threaded environment but a single PDF file cannot be used in multiple threads. So as per your requirement, you need to load one PDF file in individual thread.

//get 10 pdf file


string[] files = Directory.GetFiles(workFolder, “*.pdf”);


//case 1: sigle thread will take about 7s


foreach (var file in files)

{

AsposeToImage(file);

}

//case 2: multiple thread will take 9s

System.Threading.Tasks.

Parallel.ForEach<string>(files, new Action<string>(AsposeToImage));

//case 3: also 9s

files.ToList().ForEach(s =>

{

Thread t = new Thread(new ParameterizedThreadStart(AsposeToImage));

t.Start(s);

}

);

void

AsposeToImage(object file)

{

//Aspose.Pdf.Kit 5.3.0.0

PdfConverter pdfConverter = new PdfConverter();

pdfConverter.BindPdf(file.ToString());

pdfConverter.DoConvert();

pdfConverter.StartPage = 1;

pdfConverter.Resolution = 96;

if (pdfConverter.HasNextImage())

{

pdfConverter.GetNextImage(workFolder +

Path.GetFileNameWithoutExtension(file.ToString()) + ".png");

}

pdfConverter.Close();

}

Thank you for your reply. please review my code and where is the problem?

Hi,


Thanks for sharing the code and resource files.

I
have tested the scenario and I am able to reproduce the same performance related issue while using the product in multi-threaded environment. For the
sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-35764. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We apologize for your inconvenience.