An online image-to-PDF converter is a website that helps you convert your images to PDFs. This tool is useful because it provides an efficient way to store your images.
- HTML, CSS, and JavaScript
- NodeJS and npm
- Nodemon: Nodemon is an important Node package that'll help you develop your project faster. It helps in restarting your server when you make changes to the project.
- Express.js and express-generator: Express.js is the Nodefraemwork you'll use to build the web server. Express-generator is a library that'll help you create the necessary file and folders for Express.js to run efficiently.
- Express-session: This is an Express middleware library that'll help you manage the application sessions.
- Jade/Pug: This is a JavaScript templating engine that'll help your render the address of the uploaded images in an HTML file.
- PDFkit: This a JavaScript library that we'll use to convert the images to PDF.
- Multer: This ia a Node library that'll handle the file uploads.
- Sortablejs: This is a JavaScript drag-and-drop library that will be used in the frontend for rearranging our images before they are converted to PDF.
- Clone the Repository to your local machine using ZIP File or using the following git command:
git clone https://github.com/aniru-dh21/img2pdf.git
- Install the dependencies using
npm
after changing the present working directorycd img2pdf
:
npm install
- Run the command to access the application server:
set DEBUG=img2pdf:* & npm run devstart
-
Once you get a success message, it means the server is already running.
-
Open your web browser and type
http://localhost:3000/
in the search bar.
-
Firstly, define a route that returns the
index
HTML file when the root URL/
is reached. -
Within
index
HTML file, create a form that accepts only image file (png, jpg) and then send it to the server at a defined route. -
When the server receives the images with
Multer
, it'll store them in a folder, store the address in a session store, and redirect the request to the root URL route which will render aJade
file containing the address of the uploading images. -
Within the
Jade
file, it'll activateSortablejs
so that the user can rearrange the images before converting to PDF. There'll also be a 'convert to PDF' button which will send the address of the sorted image to the server/pdf
route. -
When the
/pdf
route receives the images, it'll usePDFkit
to convert the images to PDF. Then you'll send the address of the converted PDF. -
When the user clicks on the PDF link, the file will be downloaded to the user's device.