Browser-Based Image to PDF Converter: No Server/DB Needed

Category: Javascript | February 29, 2024
Author:rzkiypratama
Views Total:36 views
Official Page:Go to website
Last Update:February 29, 2024
License:MIT

Preview:

Browser-Based Image to PDF Converter: No Server/DB Needed

Description:

A tiny script that converts images into PDF format directly in the browser, without the need for server-side logic or database storage.

When a user selects images, the image files are converted to base64 and stored in localStorage. Then, when the user clicks the convert button, a PDF document is created using the PDF-Lib library, and each image is embedded and drawn onto PDF pages. Finally, the PDF file is constructed as a blob and made available for download.

The image to PDF converter can be used to combine scans or photos into a single PDF file for sharing or archiving. Photographers and artists can use it to convert galleries of images into printable PDF portfolios and catalogs. It can also be used to generate PDF documents from image files for business use, such as converting receipts, invoices, contracts or other documents stored as JPG/PNG files into more professional PDF versions.

How to use it:

1. Load the necessary PDF-Lib library from a CDN.

<script src="/path/to/pdf-lib.min.js"></script>

2. Build the HTML for the Image to PDF Converter.

<input type="file" id="imageFiles" accept="image/*" multiple />
<button id="convertBtn">Convert to PDF</button>
<div id="pdfDownloadLink"></div>

3. Download the package and include the main script script.js on the page. That’s it.

<script src="script.js"></script>

You Might Be Interested In:


Leave a Reply