Hello,
My apology if I have posted the same question since I could not locate the answer.
I have a jpeg file of label page (Avery #5163 - 10 of 2 by 4 labels). When converting to Pdf, the size has changed and the labels shifted around. I am not sure at the size calculation. I just want to keep the original jpg size. Am I doing something wrong here?
Please advise,
Thanks much,
An
Here is my code:
using (PdfDocument pdfDoc = new PdfDocument())
{
PdfSection section = pdfDoc.Sections.Add();
PdfPageBase page = pdfDoc.Pages.Add();
PdfImage pdfImage = PdfImage.FromFile(@"C:\BarcodeImages\20180628090713137.jpg");
float widthFitRate = pdfImage.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = pdfImage.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = pdfImage.PhysicalDimension.Width / fitRate;
float fitHeight = pdfImage.PhysicalDimension.Height / fitRate;
page.Canvas.DrawImage(pdfImage, 5, 5, fitWidth, fitHeight);
pdfFileName = $"~/PDF_FOLDER/{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf";
pdfDoc.SaveToFile(System.Web.HttpContext.Current.Server.MapPath(pdfFileName));
}