Hello
I am using PDFSharp (latest obtained via NuGet on VS2015) to create PDF that will have 1 JPG image/ page. Typically I would have 3-4 JPG image files and I need to create a PDF with each page having a single image. The size of the JPG files are around ~600-700KB, however when I add them to the page and save, a single page PDF size comes out to be around 3MB, so for a 3 page document its around 12MB. I am testing this in Release mode.
Below is the code I am using:-
Code:
s_document = new PdfDocument();
s_document.Info.Title = "Image Test PDF";
s_document.Info.Author = "Jay2017";
s_document.Info.Subject = "Auto generated PDF";
//Get all the JPG Sets for the current scan
DirectoryInfo di = new DirectoryInfo(szPath);
int i = 0;
FileInfo[] fInfo = di.GetFiles(filename + "_?.JPG");
if (fInfo.Length > 0)
{
foreach (var fi in fInfo)
{
Console.WriteLine(fi.Name);
PdfPage page = s_document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
page.Size = PdfSharp.PageSize.A4;
Image imgSrc = Image.FromFile(szPath + "\\" + fi.Name);
//If image width is larger than the threshodl value, rotate the image 90 degrees right.
if (imgSrc.Width > nImageWidth)
{
imgSrc.RotateFlip(RotateFlipType.Rotate90FlipNone);
}
else
{
noScale = true;
}
XImage image;
image = (XImage)imgSrc;
i++;
if (noScale) //Most likely ID document, so try to center it on page without scaling
{
//Page center = Pagewidth/2, Image half point = Imagewidth/2, Image left = PageHalfWidth-ImageHalfWidth
gfx.DrawImage(image, (page.Width/2)-(image.PointWidth/2), (page.Height/2)-(image.PointHeight/2));
}
else
{
//Regular A4 document, draw to full page
gfx.DrawImage(image, new XRect(0, 0, page.Width, page.Height));
}
imgSrc = null;
image = null;
}
Anyone can point me in the right direction to get the PDF file size down.
Regards
Jay