Large TIFF files (like the attached one) takes from 30 seconds to 2 minutes to get converted to PDF.
Both Memory and CPU spike full and current performance is not acceptable by the business.
System.Drawing.Image imageFile = System.Drawing.Image.FromFile(sourceFilePath);
float imageFileHeight = (float)imageFile.Height;
float imageFileWidth = (float)imageFile.Width;
imageFile.Dispose();
imageFile = null;
Pdf imagePdf = new Pdf();
#region Set PaperSize & Margin
float paperWidth = Aspose.Pdf.PageSize.A4Width;
float paperHeight = Aspose.Pdf.PageSize.A4Height;
imagePdf.PageSetup.PageHeight = paperHeight;
imagePdf.PageSetup.PageWidth = paperWidth;
#endregion
#region PDF Privileges
imagePdf.Security = new Security();
imagePdf.Security.IsAnnotationsModifyingAllowed = false;
imagePdf.Security.IsContentsModifyingAllowed = false;
imagePdf.Security.IsCopyingAllowed = false;
imagePdf.Security.IsPrintingAllowed = true;
imagePdf.Security.IsFormFillingAllowed = false;
#endregion
#region PDF Margin
Aspose.Pdf.Section addSection = imagePdf.Sections.Add();
Aspose.Pdf.Image newImage = new Aspose.Pdf.Image(addSection);
addSection.Paragraphs.Add(newImage);
addSection.PageInfo.Margin.Left = 0;
addSection.PageInfo.Margin.Right = 0;
addSection.PageInfo.Margin.Top = 0;
addSection.PageInfo.Margin.Bottom = 0;
newImage.ImageInfo.File = sourceFilePath;
#endregion
#region Image Scaling
float imageScale = 1F;
float heightScale = 1F;
float widthScale = 1F;
float fixedWidth = addSection.PageInfo.PageWidth - addSection.PageInfo.Margin.Left - addSection.PageInfo.Margin.Right;
float fixedHeight = addSection.PageInfo.PageHeight - addSection.PageInfo.Margin.Top - addSection.PageInfo.Margin.Bottom;
if (imageFileHeight > fixedHeight)
heightScale = fixedHeight / imageFileHeight;
if (imageFileWidth > fixedWidth)
widthScale = fixedWidth / imageFileWidth;
if ((heightScale != 1F) || (widthScale != 1F))
{
if ((heightScale > 1F) && (widthScale > 1F))
imageScale = 1F;
else
imageScale = heightScale < widthScale ? heightScale : widthScale;
}
newImage.ImageInfo.FixHeight = (imageFileHeight * imageScale);
newImage.ImageInfo.FixWidth = (imageFileWidth * imageScale);
#endregion
#region File Type Check
newImage.ImageInfo.ImageFileType = ImageFileType.Tiff;
newImage.ImageInfo.TiffFrame = -1;
newImage.ImageInfo.IsAllFramesInNewPage = true;
//newImage.ImageInfo.IsBlackWhite = true;
newImage.ImageInfo.CcittSubFormat = CcittSubFormat.Group4;
#endregion
imagePdf.Save(destinationFilePath);