We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting image to PDF flips the image vertically (for some photos)

I’m seeing behavior that has been reported in older posts where some images will be converted to PDF and are rotated 180 degrees. It’s bizarre in that if I open the image and simply re-save it, apparently the meta data changes for the image and will then convert properly. Here is the code and I attached the image that is causing the issue.


public void Convert(String inputFilePath, String outputFilePath)
{
var fileType = FileType.CreateFromFilePath(inputFilePath);
var pdf = new Pdf();
var margin = 20;
pdf.PageSetup.Margin.Top = margin;
pdf.PageSetup.Margin.Left = margin;
pdf.PageSetup.Margin.Right = margin;
pdf.PageSetup.Margin.Bottom = 5;
var mainSection = pdf.Sections.Add();
var image = new Image(mainSection);
mainSection.Paragraphs.Add(image);

var bitmapRepresentation = new System.Drawing.Bitmap(inputFilePath);
var scale = 1.0f;
var isLandscape = bitmapRepresentation.Width > bitmapRepresentation.Height;
mainSection.IsLandscape = isLandscape;

if (isLandscape && bitmapRepresentation.Width > mainSection.PageInfo.PageWidth)
scale = mainSection.PageInfo.PageWidth / bitmapRepresentation.Width;
else if (bitmapRepresentation.Height > mainSection.PageInfo.PageHeight)
scale = mainSection.PageInfo.PageHeight / bitmapRepresentation.Height;

image.FixedHeight = (bitmapRepresentation.Height * scale) - mainSection.PageInfo.Margin.Top - mainSection.PageInfo.Margin.Bottom;
image.FixedWidth = (bitmapRepresentation.Width * scale) - mainSection.PageInfo.Margin.Left - mainSection.PageInfo.Margin.Right;
image.ImageInfo.ImageFileType = GetImageFileType(fileType);
image.ImageInfo.SystemImage = bitmapRepresentation;
image.RotatingAngle = 0;

pdf.Save(outputFilePath);
}

<a rel=“nofollow” href=“http://www.ryadel.com/en/change-image-orientation-iphone-andor-android-phone-pics-net-c/” style=“box-sizing: border-box; background-color: rgb(255, 255, 255); color: rgb(3, 102, 214); outline-width: 0px; font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, Helvetica, Arial, sans-serif, “Apple Color Emoji”, “Segoe UI Emoji”, “Segoe UI Symbol”; font-size: 14px;”>http://www.ryadel.com/en/change-image-orientation-iphone-andor-android-phone-pics-net-c/


The orientation data in the photo was causing the issue. This post tells it nicely.

Hi Keith,


Thanks for contacting support.

I have tested the scenario and have managed to replicate the issue that while converting / adding the image to the PDF file it is rotated to 180. We are further looking into this issue and will keep you updated on the status within this forum thread. Please be patient and spare us little time.

We are sorry for this inconvenience.

Best Regards,

Hi Keith,


As I have already replicated the reported issue and after further investigation, for the sake of correction I have logged a ticket PDFNET-42650 in our issue tracking system. Product team will look into it in detail and we will give you update on the status of its correction within this forum thread.

We are sorry for this inconvenience.

Best Regards,