Images To PDF

To convert a single image to a PDF document, simply input the file path into the PdfGenerator.imageToPdf method and export the resulting PDF document.

Converting multiple images to PDF is a different process since you need an array of file paths. Use the readdir method to retrieve the directory path where image files are located.

Next, filter the file names to include only those with ".jpg" and ".jpeg" extensions. Store these filtered file names in the "jpegFiles" array.

Construct full file paths for the filtered image files by appending the directory path to each file name. Store these file paths in the "filePaths" array.

Then, use the same imageToPdf method to convert the selected images into a PDF document. The method can also takes an array of image file paths as input.

Finally, save the resulting PDF document, which contains the images, as "composite.pdf."