Change in behavior for image to PDF

Observe the two attached PDF files - both created by the same code using Aspose.pDF 4.8 and 5.0.1

The code used to auto-center and scale the images, but no more.

How do we revert to the old behavior?

Pretty sure the code below is right out of one of your samples:

Dim pdf1 As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf()
'Create a section in the Pdf object
Dim sec1 As Aspose.Pdf.Section = pdf1.Sections.Add()
'Create an image object in the section
Dim image1 As Aspose.Pdf.Image = New Aspose.Pdf.Image(sec1)

'Add image object into the Paragraphs collection of the section

'Set the path of image file
image1.ImageInfo.File = fileName
image1.ImageInfo.ImageFileType = ImageType

'Set image title
If Not title Is Nothing AndAlso title.Length > 0 Then image1.ImageInfo.Title = title

'Save the Pdf
fileName = System.IO.Path.ChangeExtension(fileName, ".pdf")


Thanks for using our products.

In above code, I am unable to notice the code lines for setting the image scale and alignment. However, you may try using ImageScale property of Image class to set the image scale value or you can also try using FixHeight and FixWidth properties of ImageInfo class to set the Height and Width of image files. More along, in order to specify the alignment of image, you may try using Alignment property of ImageInfo class. Please try using these properties and incase you still encounter any problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Please take a look over the attached PDF document that I have generated using Aspose.Pdf for .NET 5.0.1 where I have used following code lines to set the image alignment and scale values.

image1.ImageInfo.Alignment = Aspose.Pdf.AlignmentType.Center
image1.ImageScale = 0.7

First, a warning..not happy - so you have to put up with my ranting tone:

You entirely missed the point. The code used has not changed from earlier versions of Aspose.PDF, and most recently under 4.8 this exact code created AUTOMATICALLY scaled and centered images. The first of the two PDF files I sent showed this wonderful behavior.

YOU BROKE IT and now v5.0.1 no longer works the same way. Hence the second PDF, created by the same code: ugly.

The code snippet I provided comes, nearly verbatim, from

I was impressed with how perfectly this code worked - because, lets face it, when someone plops an image into a paragraph, they likely want it to all be visible. Perfect default behavior!

We both know that no single scaling factor will work with every image - the scale needs to be calculated per image: just like prior versions of Apose.PDF used to do PERFECTLY!!!

So, the "code lines for setting the image scale and alignment" that you "fail to notice" are exactly the lines of code that are missing/broken in ASPOSE.PDF.5.0.1.

For me to calculate scale, I need info about the image, which I can obtain, but I also need to know the print pixel density (DPI) and available print area, measured in pixels. Where is all this information if I suddently need to write code that I didn't need last month?

If this code has become my responsibility, I suggest you have this additional requirement added to the examples in the above referenced documentation on your site.

I appologize for the ranting tone, but I feel much better now....

Hello Stan,

Thanks for sharing the details and sorry for replying you late.

In order to test the scenario, I have extracted an image from the PDF document and as per my observations, the image scale and alignment is not being adjusted by default. In fact, the image looks right aligned because of large image scale value. By default the items in PDF document are placed in flow layout (Left-to-Right and Top-to-Bottom) and in current scenario the image is placed in top left corner. Since the image scale is too large, so its crossing the right page border. (The margin over the left side of the image is default margin).

However, I agree with your suggestion that ideally the product should automatically adjust to image scale information so that it is displayed properly. For further investigation, I have logged this problem as PDFNET-25188 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are really sorry for this inconvenience.,

PS, I tried inserting the attached image using v4.8.0 and 5.0.1 and as per my observations, the image scale was same. Can you please share the source image file so that we can test the scenario with that image file.

Source image attached. It is from a cell phone, 3264 x 1952 at 72 DPI.

I hope when you use the code above with this image and Apose.Pdf.4.8 you'll see the image centered and scaled as in the first PDF I provided. Your test run with the version of the image you extracted certainly produced different (and still not as good as I expected) results.

Please let me know...

Hello Stan,

Thanks for sharing the image file.

I have tested the scenario with Aspose.Pdf for .NET 4.8.0 while using the image file that you have shared and as per my observations, the image is automatically scaled and alignment seems to be correct. Whereas when tested the same code with v5.0.1, the image scale is increased to some higher values.(in both cases, the image left margin is same but scale value is changing the image display. Please take a look over the attached image file).

We will further test the scenario using this image and will keep you updated on the status of correction. We are sorry for this inconvenience.