I am having this issue… larger images display nicely on the pdf, but images that are smaller (e.g. 100 px width) are appearing really really small.
The code I am using is below:
'create pdf and set up pdf margins etc
Dim _pdf As Pdf = New Pdf()
Dim lic As Aspose.Pdf.License = New Aspose.Pdf.License
Try
lic.SetLicense(Server.MapPath("lics/") & "Aspose.Pdf.lic")
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex.ToString)
End Try
With _pdf
.PageSetup.Margin.Left = 20
.PageSetup.Margin.Top = 20
.PageSetup.Margin.Right = 20
.PageSetup.Margin.Bottom = 20
.CompressionLevel = 9
End With
....and to generate the image and place inside table cell:
Dim img As Aspose.Pdf.Image = New Aspose.Pdf.Image(_sc)
img.ImageInfo.ImageFileType = ImageFileType.Jpeg
img.ImageInfo.ImageStream = Me.GetIMGStream(dr("Clip_URL").ToString)
img.ImageInfo.DefaultFile = http://www.intelligentmedia.com/img/NotAvailable.gif
_rw.Cells(0).Paragraphs.Add(img)
I am attaching the resulting PDF from the above code and also the original image (the size it actually is).
As you can see the PDF image is too small. This only ocurrs with smaller images, larger ones are fine.
Also, I have attached a larger image with the corresponding PDF which was created (just to show you how the larger images display ok). For images that are too big to fit on the PDF, I am using a custom class to resize them.
Please try using the Image.ImageScale property of Image class, to specify the scale rate of the image, when placed into the Pdf file. Please add the following code line, after you have created an object of Image class.
img.ImageScale = 2.0F
If it does not resolve the problem, please feel free to contact.
The images I am loading into the PDF have varying sizes and I need to resize them accordingly. Before loading them into the PDF I am ensuring that the dimensions of the image can fit on to the page.
Since the Aspose image properties "ImageWidth" and "ImageHeight" do not return any values, it is impossible for me to determine when an image should be scaled and when it should not be.
But my question is (as you can see from the attachements) - why is the Kerrang image so small when inserted into the pdf.
What is the pixel resolution of the PDF document?
The component works just fine otherwise, but without resolving this issue there is no way I can roll this out to our client site.
If there is any other solution then please advise.
The default resolution for image is 300 PPI. You can use System.Drawing.Bitmap to get the image size and decide if you need to set the scale parameter. You can also use the ImageInfo.FixWidth to set the image with to fit the page width.