Unfortunately the result distort the image . Please attached demonstration files.
Please look carefully at the .jpg files and compare them to the pdf . the images appear to be stretched horizontally
Im assuming that
Dim h As Integer = srcImage.Height
Dim w As Integer = srcImage.Width
obtains the image size
and here it creates a pdf page which in this case may not be the correct approach
Thank you for the prompt response.
IM sorry i did not provide all of the required scenarios
How might I convert multiple source images to a single pdf pdf using your suggestion
Many Thanks
PS I have used your suggestion and note that when multiple files are converted using the following code in a loop
Dim Doc As New Document
Dim Count As Integer = 0
Dim FI As FileInfo
For Each File As String In pFilePath
Count += 1
FI = New FileInfo(File)
Select Case FI.Extension.ToLower
Case ".jpg", ".jpeg", ".png", ".bmp"
Dim page As Page = Doc.Pages.Add
Dim image As Aspose.Pdf.Image = New Aspose.Pdf.Image()
image.File = File
page.Paragraphs.Add(image)
End Select
Next
Try
Doc.Save(pNewFile)
Catch ex As Exception
Return False
Finally
If pFilePath.Count > 5 Then
SplashScreenManager.CloseForm(False)
End If
End Try
@Andre123
Sorry for the delay in replying.
The reason for the distortion is that the image does not fit horizontally. In the approach used, this can be corrected by zeroing the page margins after adding it
var bitmap = System.Drawing.Image.FromFile(dataDir + "IMG_6749.JPG");
int width = bitmap.Width;
int height = bitmap.Height;
var document = new Document();
var page = document.Pages.Add();
// For the case when it doesn’t fit horizontally.
double scaledWidth = page.PageInfo.Width - 20;
double scaledHeight = scaledWidth * height / width;
page.AddImage(dataDir + "IMG_6749.jpg", new Aspose.Pdf.Rectangle(10, 10, scaledWidth, scaledHeight));
document.Save(dataDir + "sample_image.pdf");
I used C# (since I tested it on it) - I think the gist is still clear.
Thanks Again for your response,
Unfortunately, this is not really a solution.
Whilst it may work for this single image it is likely to cause issues for other images imported as a single image or as a collection of images.
I have tried a very similar approach (which I have previously outlined) which proved to be unsatisfactory to which you offered a solution …which has now come almost full circle…eg my original request for support
It would seem that along with the outstanding issue we have already reported and not yet fixed and including this issue, the pdf solution is really not robust or to be trusted for commercial release. It does have features we require but these continuing issues in what is supposed to be a mature product is very disappointing.
For you solution to work we would need to test if the jpg file would fit to the pdf page. if not we would need to accurately compute the required pdf page size, ensure that the image is aligned correctly (taking into account pdf co-ordinates) and then insert the pdf page.
Frankly there are a number of package both commercial and free that achieve the required outcome handsomely.
@Andre123
I agree with you that it would be convenient to have an option like FitToPage and not have to calculate the transformations yourself. However, it is not that difficult - I can write you a more complete, ready-to-use code for this.
This case and why the size adjustment might not work is not clear to me, could you describe the scenario in more detail.