Pdf document to Bitmap performance problem

Hi,

couple months ago, we bought Aspose.Pdf.Kit for .Net V5.1. In our project, we need to convert each pages of a Pdf document into bitmaps and we experiencing a huge performace problem. Yesterday, I saw on the website that in V5.2, converting performance was increase so I decide to upgrade to V5.6 ans the performance still the same. Can anybody help me???

Here is the piece of code of what I'm doing:

converter.BindPdf(@"d:\Test.pdf");

converter.DoConvert();

converter.SaveAsTIFF(tiffStream);

TiffBitmapDecoder tiffDecoder = new TiffBitmapDecoder(tiffStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

After that, I loop into each frame to convert it into bitmap but the DoConvert and SaveAsTIFF seems to take a lot of time

Thank's

Hi Olivier,

You can try DecodeAllPages method of PdfViewer class to decode all the pages to Bitmaps. If this doesn’t help either then please share the input PDF file with us, so we could investigate the issue at our end. You’ll be updated with the results accordingly.

We’re sorry for the inconvenience and looking forward to help you out.
Regards,

Hi,

with V5.1

opening TEST2.PDF took 16ms and DecodeAllPages took 2599ms

with V5.6

opening TEST2.PDF took 17ms and DecodeAllPages took 2611ms

here is the piece of code I use (base on your suggestion) in my small demo to obtain those stats:

private void button2_Click(object sender, RoutedEventArgs e)

{

Bitmap[] imgs = null;

PdfViewer pdf = new PdfViewer();

Stopwatch swOpen = new Stopwatch();

swOpen.Start();

pdf.OpenPdfFile(@"d:\test2.pdf");

swOpen.Stop();

Stopwatch swDecode = new Stopwatch();

swDecode.Start();

imgs = pdf.DecodeAllPages();

swDecode.Stop();

label1.Content = pdf.PageCount.ToString() + " pages";

label2.Content = "Open: " + swOpen.ElapsedMilliseconds.ToString() + " milliseconds";

label3.Content = "Decode: " + swDecode.ElapsedMilliseconds.ToString() + " milliseconds";

radCarousel1.ItemsSource = imgs;

}

In my application, a medical application, each visit have a PDF document which contains numerized request (1, 2, 3, 4, etc... pages). The physician scroll in a grid through the visits and for each visit he stop on for a consultation, the PDF document need to be retrieve from the server an aech pages need to be convert to a bitmap to use them with my carousel.

Here is the code I use in my main application:

public class PDFToImage : PdfConverter, IDisposable

{

#region Constructors.

static PDFToImage()

{

mLicense = new License();

mLicense.SetLicense("Aspose.Pdf.Kit.lic");

}

#endregion

#region Public methods.

public void Dispose()

{

Close();

}

public void Convert(MemoryStream pPdfContent, MemoryStream pTiffStream)

{

BindPdf(pPdfContent);

DoConvert();

SaveAsTIFF(pTiffStream);

}

#endregion

#region Private fields.

static private License mLicense;

#endregion

}

private BitmapFrame[] convertPdfToImages(byte[] pPdf)

{

BitmapFrame[] imgs = null;

try

{

using (PDFToImage converter = new PDFToImage())

{

MemoryStream tiffStream = new MemoryStream();

using (MemoryStream pdfContent = new MemoryStream(pPdf))

{

converter.Convert(pdfContent, tiffStream);

TiffBitmapDecoder tiffDecoder = new TiffBitmapDecoder(tiffStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

imgs = tiffDecoder.Frames.ToArray();

}

}

}

catch (Exception exc)

{

mTracingTool.Log(GclLogger.Level.Error, "SIGNM009", "{0}", exc.ToString());

}

return imgs != null ? imgs.ToArray() : null;

}

private void pdfToImagesConverter(object pPdf)

{

CompleteScannedDocument[] docs = pPdf as CompleteScannedDocument[];

Stopwatch swConvertPdfToImages = new Stopwatch();

int i;

swConvertPdfToImages.Start();

try

{

foreach (CompleteScannedDocument doc in docs)

{

BitmapFrame[] imgs = convertPdfToImages(doc.Contents);

if (imgs != null)

{

i = 0;

foreach (BitmapFrame img in imgs)

{

i++;

InterDependencyImage theImage = new InterDependencyImage();

theImage.No = i;

theImage.TotalImages = imgs.Count();

theImage.Frame = img;

theImage.Type = doc.Type;

theImage.PrimaryImageGUID = doc.ItemGuid;

mNavigationContext.Post(delayedPdfToImageConverter, theImage);

}

}

}

}

finally

{

swConvertPdfToImages.Stop();

mTracingTool.Log(GclLogger.Level.Debug, "SIGNM018", "ConvertPdfToImages: {0}", swConvertPdfToImages.ElapsedMilliseconds.ToString() + "ms");

}

}

Thank's

Hi Olivier,

Thank you very much for sharing the PDF and code snippet with us. We’ll investigate the issue in detail and let you know with the results shortly.

We’re sorry for the inconvenience.
Regards,

Hi Olivier,

Please try to add one more line of code before executing both of the above samples:


Settings.Strategy = FileProcessingStrategy.OptimizePerformance;

If this doesn't make any difference then please do let us know, so we could further investigate and try to improve the performance. Please share that which version should our team look into. Should we try to improve the SaveAsTiff method conversion or the DecodeAllPages approach for your particular scenario.

We're sorry for the inconvenience and looking forward to help you out.
Regards,

Hi,

40 pages of text

Open: before adding line 188ms

Open: after adding line 60ms

DecodeAllPages: before adding line 24337ms

DecodeAllPages: after adding line 22873ms

**************************************

2 pages of images

Open: befopre adding line 64ms

Open: after adding line 50ms

DecodeAllPages: before adding line 2206ms

DecodeAllPages: after adding line 2183ms

Thank's

Hi Olivier,

I have logged an issue as PDFKITNET-28618 in our issue tracking system. Our team will investigate it in detail and we’ll try to improve the performance. However, I’m afraid, this kind of tasks might not be completed in short time. Nevertheless, we’ll notify you via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,