Please see the code in JPG to PDF: The image saved as rotated (Vb .NET) - support at the Imaging forum suggested I request this in this forum.
When a large image is inserted into a new PDF page, the image is resized to fit the available space on the page. This, however, is done in such a way that the height and width are resized independently, causing the image to appear “squeezed” or “stretched”.
I suggest you add a property or method to allow inserting an image while keeping the height to width ratio unchanged.
At the moment I have to do all this work myself. Some relevant snippets
oImage = Aspose.Imaging.Image.Load(filePath:=sTempFile)
Dim dProportion As Double = 1
nPageHeight = oPDF.Pages.Item(1).PageInfo.Height - oPDF.Pages.Item(1).PageInfo.Margin.Top - oPDF.Pages.Item(1).PageInfo.Margin.Bottom
nPageWidth = oPDF.Pages.Item(1).PageInfo.Width - oPDF.Pages.Item(1).PageInfo.Margin.Left - oPDF.Pages.Item(1).PageInfo.Margin.Right
If CDbl(oImage.Width) > oImage.Height Then
If (CDbl(oImage.Width) <= nPageWidth) And (CDbl(oImage.Height) <= nPageHeight) Then
'no need to do anything. Image will fit fine "as is"
Else
oImage.RotateFlip(Aspose.Imaging.RotateFlipType.Rotate90FlipNone)
End If
End If
If nPageHeight < CDbl(oImage.Height) Then
dProportion = nPageHeight / CDbl(oImage.Height)
End If
If nPageWidth < CDbl(oImage.Width) Then
If nPageWidth / CDbl(oImage.Width) < dProportion Then
dProportion = nPageWidth / CDbl(oImage.Width)
End If
End If
oStream = New IO.MemoryStream
oImage.Save(oStream)
oPDFImage = New Aspose.Pdf.Image
oPDFImage.ImageStream = oStream
If dProportion < 1 Then
oPDFImage.ImageScale = dProportion
End If
oPDF.Pages.Item(1).Paragraphs.Add(oPDFImage)
oPDF.Save(sToFileName)
It would be nice if there was a property, for example oPDFImage.KeepImageRatio with values True/False, default False to keep current functionality intact, so that I wouldn’t have to go through all that rigmarole to calculate and apply dProportion.