We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add multiple image directly

could I add multiple image to pdf when creating pdf file?


Thanks for your inquiry.

Aspose.Pdf API supports the feature to add image(s) inside PDF and you can add multiple images as well while creating PDF. Please check following code snippet with which you can add all images from a directory, inside a PDF.

Document doc = new Document();
var DirInfo = new DirectoryInfo(@"E:\\Wallpapers\\");
FileInfo[] files;
files = DirInfo.GetFiles("*.jpg");
for (int i = 0; i < files.Count(); i++)
 var currpage = doc.Pages.Add();
 FileStream imageStream = new FileStream(files[i].FullName, FileMode.Open);
 currpage.Contents.Add(new Operator.GSave());
 Aspose.Pdf.Rectangle rectangle = currpage.GetPageRect(false);
 Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY }); currpage.Contents.Add(new Operator.ConcatenateMatrix(matrix));
 XImage ximage = currpage.Resources.Images[currpage.Resources.Images.Count];
 currpage.Contents.Add(new Operator.Do(ximage.Name));
 currpage.Contents.Add(new Operator.GRestore());
doc.Save(dataDir + "output.pdf");

For more information, you may visit “Manipulate Images” article(s), in our API documentation. In case of any further assistance, please feel free to contact us.

Best Regards,
Asad Ali