C# add image to PDF

Images, Generate PDF
7/4/2014

This code sample shows how to add a image to PDF in C#

1 using( FileStream file = new FileStream("ImageFromFile.pdf", FileMode.Create, FileAccess.Write)) 2 { 3 // create a new document with a single section 4 Document document = new Document(); 5 Section section = document.Sections.Add(); 6 7 // images paths 8 string[] paths = new String[] { "pc.jpg", "handheld.jpg", "laptop.jpg" }; 9 10 // add each image to the document as an image paragraph 11 foreach ( string path in paths ) 12 { 13 // create an Image object from file 14 Image image = new Image(path); 15 16 // set layout parameters 17 image.HorizontalAlignment = HorizontalAlignment.Center; 18 image.Width = section.PageSize.Width / 3; 19 image.SpacingAfter = 10; 20 21 // add the image to the section 22 section.Paragraphs.Add( image ); 23 } 24 25 document.Write( file ); 26 }