Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Node.js Tutorial to Export Images to PDF Document With Effects Using FilePix Library in Javascript

Posted on March 10, 2023

 

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

 

 

JavaScript
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

 

 

JavaScript
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

 

 

JavaScript
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

 

 

JavaScript
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

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
let options = {
   effects: [
              {
                name: 'blur',
                config: {
                    pixels: 50
                }
              }
            ]
  };

 

 

 

 

 

Rotate Images in PDF Document

 

 

JavaScript
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

 

 

JavaScript
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 }
            }
          ]
};

 

Recent Posts

  • Node.js Tutorial to Export Images to PDF Document With Effects Using FilePix Library in Javascript
  • Node.js Tutorial to Export All Pages of PDF Document to Images and Save it in Javascript
  • Node.js OfficeGen Example to Add Text & Images in Powerpoint Presentation in Javascript
  • Node.js OfficeGen Example to Generate Excel Files By Adding Data inside Cells & Sheets in Javascript
  • Node.js OfficeGen Example to Create Word Docx Files & Add Text Images inside it Using Javascript
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme