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