We are converting jpg and png images to PDF with Aspose.
When converting with the following code, the size of the output file becomes 31.5M whe the starting total size of all png images together was just 1.3M. How can that even be? And images are binary (black and white).
I am attaching the input png images (it does not contain any private material). Output is just too big.
Decreasing the image quality is not an option since it totally destroys the conversion of low quality images and triples the time the conversion needs to process them.
Code:
var doc = new Aspose.Pdf.Document();
foreach (DsDocumentAttachment.TFileDataRow row in filesInCurrentAttachment.Rows)
{
// custom get stream of each image from DB
var imageStream = new MemoryStream(newDocument.fMain.Attachment_GetFileData(row.FileDataID, true, true, true, false).Blob);
var bitmap = new Bitmap(imageStream);
if (bitmap != null)
{
var page = doc.Pages.Add();
page.PageInfo.Margin.Top = page.PageInfo.Margin.Right = page.PageInfo.Margin.Bottom = page.PageInfo.Margin.Left = 0;
page.PageInfo.Height = bitmap.Height;
page.PageInfo.Width = bitmap.Width;
var pdfImage = new Aspose.Pdf.Image();
page.Paragraphs.Add(pdfImage);
pdfImage.ImageStream = imageStream;
}
}
doc.Convert(new MemoryStream(), PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
var returnStream = new MemoryStream();
doc.Save(returnStream);
// saving stream as an array (returnStream.ToArray()) to DB
input
document.zip (1.3 MB)