Jpg distorted when converted to PDF

Hi Guys
Im using the following aspose suggested code to convert jpg files to pdf

Dim srcImage As System.Drawing.Image = System.Drawing.Image.FromFile(File)
Dim h As Integer = srcImage.Height
Dim w As Integer = srcImage.Width

Dim page As Page = Doc.Pages.Add
Dim image As Aspose.Pdf.Image = New Aspose.Pdf.Image()
image.File = File

page.PageInfo.Height = h
page.PageInfo.Width = w

page.PageInfo.Margin.Bottom = (0)
page.PageInfo.Margin.Top = (0)
page.PageInfo.Margin.Right = (0)
page.PageInfo.Margin.Left = (0)

page.Paragraphs.Add(image)

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

page.PageInfo.Margin.Bottom = (0)
page.PageInfo.Margin.Top = (0)
page.PageInfo.Margin.Right = (0)
page.PageInfo.Margin.Left = (0)

What am i missing or could you suggest an alternate approach

many thanks
IMG_6748.JPG (338.9 KB)

IMG_6749.JPG (654.7 KB)

The PDF is the result file
Sample.pdf (2.8 MB)

@Andre123
When using the approach described here, the resulting document maintains proportions.

ImagetoPDF_out.pdf (340.7 KB)

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

The resulting PDF displays
Soil Test Report.pdf (3.4 MB)

the images incorrectly however in this case the image is shrunk horizontally

The last photo of the recycle bin is the most obvious example

@Andre123
Thanks for the clarification, I will study it and write to you later.

@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

Page page = doc.Pages.Add();
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;

or by setting the image scaling

image.File = File;
image.ImageScale = 0.25;

The variant with more control looks like this:

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.

What can be done to fix this issue?

@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.