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 !
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,
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.