Hi Asad ali,
Now are facing the performance issue in With out Compression also. we process the 1200 Pages of images and creates the PDF File size with 32MB Max and it we creates the PDFs. This is having performance issue. It takes 15-20 minutes in our application. We used Latest version of Aspose.PDF.Dll v 17.6
Performance issue without Compression - 15-20Min to process Single item with 1200 Pages.
Performance issue with Compression - More than 30min to process Single item with 1200 Pages.
Please provide both fixes as soon.
Please find below my code snippet.
private void CreatePDF(ref R2Item r2Item)
{
this.ClientStatusMessage = string.Format("Retrieving Images ...", r2Item.ItemName);
Document doc = new Document();
int pdfCount = 1;
int nPageCount = 0;
int nOptimizePageCount = 0;
ListPageCount = new Dictionary<string, Int32>();
tempLocalPDFPath = Path.GetTempPath() + r2Item.ItemName;
if (Directory.Exists(tempLocalPDFPath))
Directory.Delete(tempLocalPDFPath, true);
Directory.CreateDirectory(tempLocalPDFPath);
nOptimizePageCount = Convert.ToInt32(ConfigurationManager.AppSettings["OptimizePageCount"].ToString());
for (int i = 0; i < r2Item.FileList.Count; i++)
{
if (r2Item.FileList[i].AttachmentType.ToUpper().Trim() == "IMAGE")
{
try
{
nPageCount++;
MemoryStream ms = new MemoryStream();
AddPDFPage(doc, r2Item.FileList[i].FileBytes);
doc.Save(ms);
if (ConfigurationManager.AppSettings["RequiredOptimize"].ToString() == "true")
{
ms.Seek(0, SeekOrigin.Begin);
doc = new Document(ms);
OptimizePDFDocument(ref doc);
ms.Flush();
doc.Save(ms);
}
long filesize = ms.Length;
if (i == r2Item.FileList.Count-1)
{
this.ClientStatusMessage = string.Format("Saving... {0} ", r2Item.ItemName + "_" + pdfCount.ToString().PadLeft(3, '0') + ".pdf");
doc.Save(tempLocalPDFPath + "\\" + r2Item.ItemName + "_" + pdfCount.ToString().PadLeft(3, '0') + ".pdf");
ListPageCount.Add(r2Item.ItemName + "_" + pdfCount.ToString().PadLeft(3, '0') + ".pdf", nPageCount);
}
else if ((filesize / (1024 * 1024)) < Convert.ToInt32(ConfigurationManager.AppSettings["PDFFileThrusholdSize"].ToString()))
continue;
else
{
//Storing the PDF file in Item Temp path
this.ClientStatusMessage = string.Format("Saving... {0} ", r2Item.ItemName + "_" + pdfCount.ToString().PadLeft(3, '0') + ".pdf");
doc.Save(tempLocalPDFPath + "\\" + r2Item.ItemName + "_" + pdfCount.ToString().PadLeft(3, '0') + ".pdf");
ListPageCount.Add(r2Item.ItemName + "_" + pdfCount.ToString().PadLeft(3, '0') + ".pdf", nPageCount);
pdfCount++;
nPageCount = 0;
doc = new Document();
AddPDFPage(doc, r2Item.FileList[0].FileBytes);
nPageCount++;
}
}
finally
{
}
}
}
}
private void AddPDFPage(Document doc, byte[] fileByte)
{
var currpage = doc.Pages.Add();
MemoryStream imageStream = new MemoryStream(fileByte);
currpage.Resources.Images.Add(imageStream);
currpage.Contents.Add(new Operator.GSave());
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
currpage.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = currpage.Resources.Images[currpage.Resources.Images.Count];
currpage.Contents.Add(new Operator.Do(ximage.Name));
currpage.Contents.Add(new Operator.GRestore());
}
private void OptimizePDFDocument(ref Document file)
{
Document pdfDocument = file;
pdfDocument.OptimizeResources(new Document.OptimizationOptions()
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true,
CompressImages = true,
ImageQuality = 70
});
file = pdfDocument;
}
Please review this code. Please let me know if there is any changes required. In the above code.
Please provide solution as soon. We are having issue with Production. Our Customer is not happy with this issue.
Thanks
P. Saravanan.