Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have number of images in a folder.I want to address the folder in c# and then all the images become a single pdf.
How can I do it with free component?
Posted

I am using PDFSharp. If you use it then you can try the following code:

using(PdfDocument doc = new PdfDocument())
{
 using(Image myimage = Image.FromFile(ImageFilePath))
 {
  PdfPage page = new PdfPage();
  page.Width = myimage.Width + 20;
  page.Height = myimage.Height + 20;
  doc.Pages.Add(page);

  XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
  XImage img = XImage.FromFile(fileName);

  xgr.DrawImage(img, 10, 10, myimage.Width, myimage.Height);
  doc.Save(PathToSavePDFDoc);
  doc.Close();
 }
}



To get information on PDFSharp go to http://www.pdfsharp.net/wiki/[^]
 
Share this answer
 
v2
Comments
MJ MOUSAVI 18-Apr-13 11:00am    
Can I compress pdf file?
gaurav_mittal 25-Apr-13 4:30am    
I am using DotNetZip library for compressing the pdf and encrypting the zip file. You may try it with the following code:

using(var zip = new Ionic.Zip.ZipFile())
{
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.Encryption = EncryptionAlgorithm.WinZipAes128;
zip.Password = passKeyZIP;
zip.AddFile(finalPDFFullPath, "");
zip.Save(zipFilePath);
}

DotNetZip Library can be found at

http://dotnetzip.codeplex.com/


Try to have a look at
Converting Image Files to PDF[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900