Add Multiple Images into one pdf

Is there any way I can add multiple images to pdf to create it, and also if I can improve the image by a certain setting before generated pdf?

linzi201719811001:
Is there any way I can add multiple images to pdf to create it

Hi Aaron,

Thanks for contacting support.

In order to accomplish your requirement, please try following the instructions specified over Add Image to Existing PDF File. In order to add more than one image, add page to Pages collection of PDF file and then add the newly loaded image to specific page instance.
linzi201719811001:
, and also if I can improve the image by a certain setting before generated pdf?
In order to deal with images, we have a separate API named Aspose.Imaging which can be used for Manipulating Images.

Should you have any further query, please feel free to contact.

Hi codewarior,


I refer to Add Image to Existing PDF File, but it looks like there already exists one pdf and then open that pdf to insert multiple image. I want to know if there’s method that support inserting multiple image only when creating pdf file
Hi Aaron,

The Document class offers the feature to create as well as manipulate existing PDF files. So as per your requirement, you can instantiate Document instance without passing any parameter and as shared earlier, add pages to Pages collection of Document instance. Once pages are added, the next step is to add image to paragraphs collection of each page instance.

Hi Aaron,

Please try using following code snippet to fulfill your requirements.

[C#]

// get images names from specific folder
string[] files = Directory.GetFiles(@"C:\pdftest\Images\");
// create Document instnace
Document doc = new Document();
// iterate through all image names loaded earlier
foreach (string file in files)
{
    // add page to pages collection of PDF file
    Page asposePage = doc.Pages.Add();
    // create Imate object
    Aspose.Pdf.Image image = new Aspose.Pdf.Image();
    // set image file path
    image.File = file;
    // add image to paragraphs collection of Page instance
    asposePage.Paragraphs.Add(image);
}

// save resultant PDF file
doc.Save(“c:/ pdftest / Images_in_PDF.pdf”);