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

Free Support Forum - aspose.com

Convert large pdf to image in parallel

Hi,

We do the following

DocumentpdfAsposeDocument = new Document(“input.pdf”);
Resolution resolution = new Resolution(162);

for (int i=0; i< pageNumberOfPDF; I++){
Page pageForAsposePdf = pdfAsposeDocument.getPages().get_Item(i);
JpegDevice jpegDevice = new JpegDevice(resolution,162);
Page pageForAsposePdf; // Some code for this , ignore here
OutputStream output ; // Some code for this , ignore here
jpegDevice.process(pageForAsposePdf, output);
}
if the file is large, let’s say 200 + pages, it will take 15-20 minutes,
Any good advice for the performance improvement?

Could do it parallel such as multiple thread to finish the conversion to speed up?

Thanks for help!

Ruhong

@ruhongcai

Thank you for contacting support.

Please note that Aspose.PDF for .NET is multi-thread safe as long as single thread works on a single document at a time. Which means access to single document by multiple threads at the same time is not supported. Therefore, you may split large files into several smaller ones and then proceed further accordingly.

A simple and basic example to split a 10 page PDF document into two different PDF documents, each containing five pages. You may further enhance the code as per your requirements.

ByteArrayOutputStream output1 = new ByteArrayOutputStream();
ByteArrayOutputStream output2 = new ByteArrayOutputStream();
ArrayList<com.aspose.pdf.Page> list = new ArrayList<com.aspose.pdf.Page>();
Document document = new Document(dataDir + "10pages.pdf");
Document split1 = new Document();
Document split2 = new Document();
int counter = 1;
for (int i = 0; i<5; i++)
{
    list.add(i , document.getPages().get_Item(counter));
    counter++;
}
split1.getPages().insert(1, list);
list.clear();
for (int i = 0; i<5; i++)
{
    list.add(i , document.getPages().get_Item(counter));
    if (counter < document.getPages().size())
    {
        counter++;
    }
}
split2.getPages().insert(1 , list);

//Saving the file on disk
split1.save(dataDir + "5pages_1.pdf");
// Save file to stream object
split1.save(output1);

//Saving the file on disk
split2.save(dataDir + "5pages_2.pdf");
// Save file to stream object
split2.save(output2);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.