@Kodofix
Thanks for contacting support.
You may calibrate image during JPG to PDF conversion through different ways. For instance, you may either adjust height/width of the page equal to height/width of the image, or adjust height/width of the image according to desired page height/width.
Please check following sample code snippet(s), where I have generated PDF from JPG through both ways, mentioned above.
Adjust Page Height/Width
var pdf = new Aspose.Pdf.Document();
var pdfImageSection = pdf.Pages.Add();
FileStream stream = new FileStream("inFile.jpg", FileMode.Open);
var image = new Aspose.Pdf.Image { ImageStream = stream };
var bmp = new System.Drawing.Bitmap(stream);
pdfImageSection.PageInfo.Width = bmp.Width;
pdfImageSection.PageInfo.Height = bmp.Height;
pdfImageSection.Paragraphs.Add(image);
// remove extra white space in four corners by setting page margin information
pdfImageSection.PageInfo.Margin.Left = pdfImageSection.PageInfo.Margin.Right = pdfImageSection.PageInfo.Margin.Top = pdfImageSection.PageInfo.Margin.Bottom = 0f;
pdf.Save(dataDir + "outFile.pdf");
Scale Input Image
var pdf = new Aspose.Pdf.Document();
var pdfImageSection = pdf.Pages.Add();
FileStream stream = new FileStream("inFile.jpg", FileMode.Open);
System.Drawing.Image img = new Bitmap(stream);
img = ScaleImage(img, (int)pdfImageSection.PageInfo.Width, (int)pdfImageSection.PageInfo.Height);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
var image = new Aspose.Pdf.Image { ImageStream = ms };
pdfImageSection.Paragraphs.Add(image);
pdfImageSection.PageInfo.Margin.Left = pdfImageSection.PageInfo.Margin.Right = pdfImageSection.PageInfo.Margin.Top = pdfImageSection.PageInfo.Margin.Bottom = 0;
pdf.Save(dataDir + "outFile.pdf");
Definition of ScaleImage(…) method
public static System.Drawing.Image ScaleImage(System.Drawing.Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
using (var graphics = Graphics.FromImage(newImage))
graphics.DrawImage(image, 0, 0, newWidth, newHeight);
return newImage;
}
In case of any further assistance, please feel free to let us know.