- 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
Edit PDF Guide
How to integrate the PDF Editor into your application using iLovePDF’s REST API to add text, images and elements to PDF.
New to the API? Start with Processing a PDF: every tool guide builds on its task flow.
Basic Edit PDF
The following example will show you how to add text elements to a PDF document. Take into account that by simply adding a text element, it will come with properties by default.
You can learn more about how to customize element properties later in the advanced section.
// Create a new task
$editpdfTask = $ilovepdf->newTask('editpdf');
// Add files to task for upload
$pdfFile = $editpdfTask->addFile('path/to/file1_name.pdf');
// Create an element
$textElem = new TextElement();
// Set your element options
$textElem->setText("Sample text");
// Add text element to task
$editpdfTask->addElement($textElem);
// Execute the task
$editpdfTask->execute();
// Download the package files
$editpdfTask->download();// Under construction# Under constructionconst task = ilovepdf.newTask('editpdf') as EditTask;
task.start()
.then(() => {
const file = new ILovePDFFile(
path.resolve('path/to/file1_name.pdf')
);
return task.addFile(file);
})
.then(() => {
const textElement = new Text({
coordinates: { x: 100, y: 100 },
dimensions: { w: 100, h: 100 },
text: 'test',
});
return task.addElement(textElement);
})
.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 the whole process of creating the editpdf task (uploading your PDF, processing it and downloading it) works as explained in Processing a PDF, let’s focus on creating elements.
There are a few elements that can be added to a PDF: text, image or svg. Use the associated class to create the corresponding element, modify its properties if required and add it to the task. After doing this, your task is ready to process and the output PDF will include the new element.
Now it’s time to see the properties you can set on each element.
Advanced Edit PDF
First, take a look at the properties applicable to any element:
- pages sets at which pages the element/s will be applied to. Cannot be less than 1.
- rotation sets the rotation of the element/s in degrees. From 0 to 360.
- opacity sets the opacity of the element/s. From 1 to 100.
- coordinates sets the position of the element in x,y coordinates. If no coordinates are specified, the element will be placed in the center of the page by default.
- zindex sets the stack order of the element in case of overlapping.
These properties will customize an element, no matter the type. However, the API also provides properties related specifically to text. See the following:
Text properties
- text assigns a text string to the element.
- text_align sets the text alignment. Can be left (default), center or right.
- font_family sets the text font type.
- font_color sets a color for text. Accepts both string and hex value like #000000.
- font_size sets a size in points for text.
- font_style sets font style.
- letter_spacing sets the space between characters in text. By default it is 0. Negative values are accepted until -20.