- Get started
- Overview
- Getting started
- Processing a PDF
- Common functions
- Error handling
- Organize
-
Merge PDF
-
Split PDF
-
Smart Split PDF (AI)
-
Rotate PDF
-
Add page numbers
- Optimize
-
Compress PDF
-
Repair PDF
-
PDF to PDF/A
-
Validate PDF/A
- Convert
-
Office to PDF
-
HTML to PDF
-
Images to PDF
-
PDF to JPG
- Edit and secure
-
Edit PDF
-
Watermark PDF
-
Protect PDF
-
Unlock PDF
- AI and data
-
OCR PDF
-
Extract text
-
PDF to Markdown (AI)
-
AI Summarizer (AI)
-
Detect forms (AI)
- No matches.
Resources
Convert Images to PDF Guide
Develop your own solution to convert JPG, JPEG, PNG, TIF and TIFF to PDF by integrating with iLovePDF’s REST API.
New to the API? Start with Processing a PDF: every tool guide builds on its task flow.
Basic images to PDF conversion
You can easily convert JPG, PNG and TIFF images to PDF files like this:
// Create a new task
$myTaskConvertJPG = $ilovepdf->newTask('imagepdf');
// Add files to task for upload
$file1 = $myTaskConvertJPG->addFile('path/to/image1_name.jpg');
$file2 = $myTaskConvertJPG->addFile('path/to/image2_name.png');
// Execute the task
$myTaskConvertJPG->execute();
// Download the package files
$myTaskConvertJPG->download();// Create a new task
var taskImageToPDF = api.CreateTask<ImageToPdfTask>();
// Add files to task for upload
var file1 = taskImageToPDF.AddFile("image1.jpg");
var file2 = taskImageToPDF.AddFile("image2.png");
// Execute the task
taskImageToPDF.Process();
// Download the package files
taskImageToPDF.DownloadFile();# Create a new task
my_task_convert_jpg = ilovepdf.new_task :imagepdf
# Add files to task for upload
file1 = my_task_convert_jpg.add_file 'path/to/image1_name.jpg'
file2 = my_task_convert_jpg.add_file 'path/to/image2_name.png'
# Execute the task
my_task_convert_jpg.execute
# Download the package files
my_task_convert_jpg.downloadconst task = ilovepdf.newTask('imagepdf') as ImagePdfTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/image1_name.jpg'));
})
.then(() => {
return task.addFile(new ILovePDFFile('path/to/image2_name.png'));
})
.then(() => {
return task.process();
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsAs a result, you will get a single PDF file with one page per image. By default, all images are merged into one PDF (see merge_after below).
Advanced images to PDF conversion
You can customize some options of your image to PDF conversion with the following properties:
Change PDF orientation
// Choose your processing tool
$myTaskConvertJPG = $ilovepdf->newTask('imagepdf');
// Set your tool options
$myTaskConvertJPG->setOrientation('landscape');// Choose your processing tool
var taskImageToPDF = api.CreateTask<ImageToPdfTask>();
// Set your tool options
taskImageToPDF.Process(new ImageToPdfParams{Orientation = Orientations.Landscape});# Choose your processing tool
my_task_convert_jpg = ilovepdf.new_task :imagepdf
# Set your tool options
my_task_convert_jpg.orientation = 'landscape'const task = ilovepdf.newTask('imagepdf') as ImagePdfTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.jpg'));
})
.then(() => {
return task.process({ orientation: 'landscape' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsWith orientation you can change your final PDF file from portrait to landscape and vice versa. This may be useful depending on the size ratio of your converted images. Note that this function will change the orientation of your final PDF file, not the original images.
If you want to rotate your images before converting them to PDF, you need to use the rotate property for every uploaded file, as we have seen in previous guides.
$file1->setRotation(270);var file1 = taskImageToPDF.AddFile("path/to/image1_name.jpg", taskImageToPDF.TaskId, Rotate.Degrees270);file1.rotate = 270const task = ilovepdf.newTask('imagepdf') as ImagePdfTask;
task.start()
.then(() => {
const file = new ILovePDFFile('path/to/file1_name.jpg');
file.params.rotate = 270;
return task.addFile(file);
})
.then(() => {
return task.process();
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsThere are four rotation orientations to choose from:
- 0 degrees
- 90 degrees
- 180 degrees
- 270 degrees
Set page margin
// Choose your processing tool
$myTaskConvertJPG = $ilovepdf->newTask('imagepdf');
// Set your tool options
$myTaskConvertJPG->setMargin(20);// Choose your processing tool
var taskImageToPDF = api.CreateTask<ImageToPdfTask>();
// Set your tool options
taskImageToPDF.Process(new ImageToPdfParams{Margin = 20});# Choose your processing tool
my_task_convert_jpg = ilovepdf.new_task :imagepdf
# Set your tool options
my_task_convert_jpg.margin = 20const task = ilovepdf.newTask('imagepdf') as ImagePdfTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.jpg'));
})
.then(() => {
return task.process({ margin: 20 });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsmargin allows you to set a margin between the PDF page and its contained image. If you don’t set any margin, your final PDF will be as big as the original image.
Set page size
// Choose your processing tool
$myTaskConvertJPG = $ilovepdf->newTask('imagepdf');
// Set your tool options
$myTaskConvertJPG->setPagesize('A4');// Choose your processing tool
var taskImageToPDF = api.CreateTask<ImageToPdfTask>();
// Set your tool options
taskImageToPDF.Process(new ImageToPdfParams{PageSize = PageSizes.A4});# Choose your processing tool
my_task_convert_jpg = ilovepdf.new_task :imagepdf
# Set your tool options
my_task_convert_jpg.pagesize = 'A4'const task = ilovepdf.newTask('imagepdf') as ImagePdfTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.jpg'));
})
.then(() => {
return task.process({ pagesize: 'A4' });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsOne way to set your final PDF document’s page size is by forcing it with pagesize. You have three standard sizes to choose from:
- A4 creates a final document with A4-standard size and the image filling it
- letter creates a final document with Letter-standard size and the image filling it
- fit creates a final document with the same size as the original image. This is the default option.
Merge all images in a single PDF
// Choose your processing tool
$myTaskConvertJPG = $ilovepdf->newTask('imagepdf');
// Set your tool options
$myTaskConvertJPG->setMergeAfter(true);// Choose your processing tool
var taskImageToPDF = api.CreateTask<ImageToPdfTask>();
// Set your tool options
taskImageToPDF.Process(new ImageToPdfParams{MergeAfter = true});# Choose your processing tool
my_task_convert_jpg = ilovepdf.new_task :imagepdf
# Set your tool options
my_task_convert_jpg.merge_after = trueconst task = ilovepdf.newTask('imagepdf') as ImagePdfTask;
task.start()
.then(() => {
return task.addFile(new ILovePDFFile('path/to/file1_name.jpg'));
})
.then(() => {
return task.process({ merge_after: true });
})
.then(() => {
return task.download();
})
.then((data) => {
fs.writeFileSync('path/to/local/file_name.pdf', data);
});composer require ilovepdf/ilovepdf-phpdotnet add package ILove_PDFgem install ilovepdfnpm install @ilovepdf/ilovepdf-nodejsSetting merge_after to true (the default) serves all converted images in a single PDF. Set it to false to get a separate PDF for every image. Note that if you combine this with pagesize, you will have different results.
That is all you need to know about Image to PDF conversion.