Hi!
I'm working on a project in C# which involves converting different types of docs into one single PDF.
For image conversion, i use PDFSharp (which is great btw), but I noticed an issue.
So, I have this function:
Code:
public static void ImageToPdf(string fileNameInput, string fileNameOutput)
{
try
{
PdfDocument doc = new PdfDocument();
TiffImageSplitter tiff = new TiffImageSplitter();
int pageCount = tiff.getPageCount(fileNameInput);
for (int i = 0; i < pageCount; i++)
{
PdfPage page = new PdfPage();
System.Drawing.Image tiffImg = tiff.getTiffImage(fileNameInput, i);
XImage img = XImage.FromGdiPlusImage(tiffImg);
// Scale img
double originalAspectRatio = (double)img.PixelWidth / (double)img.PixelHeight;
double customAspectRatio = 1;
if (originalAspectRatio >= customAspectRatio)
{
page.Width = 700;
page.Height = img.PointHeight / (img.PointWidth / 700);
}
else
{
page.Width = img.PointWidth / (img.PointHeight / 700);
page.Height = 700;
}
doc.Pages.Add(page);
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]);
// Draw it scaled
xgr.DrawImage(img, 0, 0, page.Width, page.Height);
}
doc.Save(fileNameOutput);
doc.Close();
}
catch { throw; }
}
The function works fine, but (there's always a but!) with or without image scaling (resizing), the PDF file size remains the same (ex: for about 4 .jpg's of ~1Mb each => ~30mb pdf, and the same size even if the images were scaled!)
Did I missed smth? Or...
I'm expecting that after the images have been scaled, the pdf file size to be smaller. That's the main reason why I'm scaling them.
Thanks,
Teslo.