I have a class that extracts a page from a PDF file, rotates the page, and hands a memorystream back to the caller. I am finding that the initial call to perform the extract/rotate takes about 1.2 seconds, and subsequent attempts to the same calls take between .07 seconds and .1 seconds. I know I am talking about fractions of a second, but the fractions are noticable in my environment. I have been trying to figure out if there is any way for me to initialize and bring the time delay into the init of my class rather than when a user is trying to actually use the function, but have not had much luck. I have attached the relavent portions of the class. It is more complicated than it needs to be at this point simply becuase I have been trying to pinpoint where I am seeing the performance hit.
Any ideas on how to get this delay to happen on init rather than on the first call to the methods in question? PDF.Kit version is 3.2.0.0.
public class PageManager
{
PdfFileEditor fEdit;
MemoryStream input;
PdfPageEditor pEdit;
///
/// Rotate a pdf page.
///
/// Path and file name to the PDF image.
/// Page number to rotate (1 based).
/// Numeric value for rotation (90, 180, 270).
/// MemoryStream
public MemoryStream RotatePage(String FilePath, Int32 Page, Int32 Rotation)
{
if (input == null)
{
Byte[] inputBytes = File.ReadAllBytes(@FilePath);
input.Write(inputBytes, 0, inputBytes.Length);
input.Seek(0, 0);
}
MemoryStream output = new MemoryStream();
fEdit.Extract(input, new int[] { Page }, output);
pEdit.BindPdf(output);
pEdit.Pages = new Int32[] { 1 };
pEdit.Rotation = Rotation;
pEdit.Save(output);
return output;
}
public PageManager()
{
fEdit = new PdfFileEditor();
input = new MemoryStream();
pEdit = new PdfPageEditor();
}
public PageManager(String FilePath)
{
if (File.Exists(FilePath))
{
fEdit = new PdfFileEditor();
input = new MemoryStream();
pEdit = new PdfPageEditor();
inputBytes = File.ReadAllBytes(@FilePath);
input.Write(inputBytes, 0, inputBytes.Length);
input.Seek(0, 0);
}
}
private Byte[] inputBytes { get; set; }
}