IsLandscape destroys the image quality

Hello,

I create PDF from image in various resolutions, the problem is that when I set the PDF into landscape mode the quality of the image is destroyed.
I tried it with the latest version (9.9.0) with the same result.

For example, an image with resolution 1176 (width) and 1058 (height).

The code :

var pdf = new Pdf();
pdf.CompressionLevel = 0;
pdf.IsLandscape = true;
pdf.PageSetup.Margin.Top = 0;
pdf.PageSetup.Margin.Right = 0;
pdf.PageSetup.Margin.Bottom = 0;
pdf.PageSetup.Margin.Left = 0;
foreach (var img in images)
{
if (!ImpressionControlHelper.AllOneColor((Bitmap)img))
{
var sec = pdf.Sections.Add();
//sec.IsLandscape = true;
var image = new Aspose.Pdf.Generator.Image(sec);
sec.Paragraphs.Add(image);
image.ImageInfo.ImageStream = new MemoryStream(ImpressionControlHelper.ImageToByteArray(img));
image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;
}
}
return pdf.GetBuffer();

Thank you for your help !

Hi Joel,


Thanks for your inquiry. I have tested the scenario using new DOM approach for image to PDF conversion and unable to notice the quality issue. Please use new DOM approach for image to PDF conversion, it will resolve the issue. If issue persist then please share your sample image here, we will look into it and will provide information accordingly.

Best Regards,

Thank you for your answer.

So I went to the new method. Unfortunately, I have a problem at the end when I need to have an array of bytes.
I can’t use SaveFormat.Pdf in my version of Aspose.Pdf (8.4.0.0), how can I convert my Aspose.Pdf.Document to a Pdf ?


The code :

var doc = new Aspose.Pdf.Document();

var page = doc.Pages.Add();

page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;

foreach (var img in images)
{
if (!ImpressionControlHelper.AllOneColor((Bitmap)img))
{
page.CropBox = new Aspose.Pdf.Rectangle(0, 0, img.Width, img.Height);

var image = new Aspose.Pdf.Image();

page.Paragraphs.Add(image);

image.ImageStream = new MemoryStream(ImpressionControlHelper.ImageToByteArray(img));
}
}

var outStream = new MemoryStream();

doc.Save(outStream, SaveFormat.Pdf);
=> I can’t use this in my version

return outStream.ToArray();



Best Regards

Hi Joel,


Thanks for your feedback. Please note we maintain a single code base of Aspose components. All fixes and improvements made in latest release. so I am afraid we can not provide you solution for old version. Either you may try to save PDF into stream without SaveFormat parameter or upgrade to latest version of Aspose.Pdf for .NET. We are truly sorry for the inconvenience caused.

Best Regards,

Hi Joel,


Adding more to Tilal’s comments, when using Aspose.Pdf.Document instance, the default output generated by this API is in PDF format, so you do not need to specify the output file format (unless your requirement is to save the output in format other than default PDF). So you may skip the second argument in Document.Save(…) method.