Welcome folks today in this blog post we will be exporting multiple images to pdf
document with effects
using the filepix
library in javascript. All the full source code of the application is shown below.
Get Started
In order to get started you need to make a new node.js
project using the below command as shown below
npm init -y
npm i filepix
And after that you need to make an index.js
file and copy paste the following code
index.js
1 2 3 |
let filepix = require('filepix') filepix.img2PDF(pages = './uploads', output = "output.pdf"); |
As you can see in the above javascript
code we are first of all importing the filepix
library and then we are using the img2PDF()
method to export the multiple images
stored inside the uploads
directory to create the output.pdf
file
Or you can specify different images
using their paths inside the array as shown below
1 2 3 4 5 6 7 |
filepix.img2PDF( pages = [ './1.jpg', './public/upload/2.jpg', './public/upload/example/3.jpg' ], output = "./outputImageDir/output.pdf"); |
Applying Effects to Images in PDF Document
Now you can apply different effects
to the images which you will be inserting inside the pdf
document as shown below
First of all we will be changing the color
of the images which will be there in the pdf
document as shown below
1 2 3 4 5 6 7 8 9 10 11 12 |
let filepix = require('filepix') let options = { effects: [ { name: 'color', config: [{ apply: 'green', params: [100] }] } ] }; filepix.img2PDF(pages = './uploads', output = "output.pdf",options); |
As you can see we are passing the third
option which is the options
object that we construct in which we have the effects
object in which we specify the name
of the filter or effect which is the color
and inside it we are providing the config
object in which we are changing the color of the pdf
document or images.
Flipping the Images
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
let options = { effects: [ { name: 'mirror' } ] }; let options = { effects: [ { name: 'flip', config: { vertical: true } } ] }; |
Blur Images
1 2 3 4 5 6 7 8 9 10 |
let options = { effects: [ { name: 'blur', config: { pixels: 50 } } ] }; |
Rotate Images in PDF Document
1 2 3 4 5 6 7 8 9 10 |
let options = { effects: [ { name: 'rotate', config: { ratio: 45 } } ] }; |
Merging Multiple Effects
You can even merge or add
multiple filters and effects by specifying them inside the options as shown below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
let options = { effects: [ { name: 'quality', config: { ratio: 10 } }, { name: 'contrast', config: { ratio: 0.2 } }, { name: 'threshold', config: { max: 200 } } ] }; |