From c9372942baf077fe9d518e9fd6914b394249b227 Mon Sep 17 00:00:00 2001 From: "codeshwar-preview[bot]" <160849357+codeshwar-preview[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:19:03 +0000 Subject: [PATCH] Update files in add-38 --- ILuvImages/public/convert_to_jpg.html | 40 ++++++++++++++++++++------- ILuvImages/public/index.html | 4 ++- ILuvImages/public/js/imageToPdf.js | 22 +++++++++++++++ 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 ILuvImages/public/js/imageToPdf.js diff --git a/ILuvImages/public/convert_to_jpg.html b/ILuvImages/public/convert_to_jpg.html index 25e0c5e..e649649 100644 --- a/ILuvImages/public/convert_to_jpg.html +++ b/ILuvImages/public/convert_to_jpg.html @@ -15,6 +15,7 @@

Convert Image to JPG Format

+
@@ -22,6 +23,7 @@

Convert Image to JPG Format

+ - \ No newline at end of file + + \ No newline at end of file diff --git a/ILuvImages/public/index.html b/ILuvImages/public/index.html index f6cb3d7..9c136df 100644 --- a/ILuvImages/public/index.html +++ b/ILuvImages/public/index.html @@ -19,11 +19,13 @@

Welcome to ILuvImages

Apply Filter Compress Image Crop Image + Convert Image to PDF - + + \ No newline at end of file diff --git a/ILuvImages/public/js/imageToPdf.js b/ILuvImages/public/js/imageToPdf.js new file mode 100644 index 0000000..ed60add --- /dev/null +++ b/ILuvImages/public/js/imageToPdf.js @@ -0,0 +1,22 @@ +// imageToPdf.js + +// Import necessary libraries +import jsPDF from 'jspdf'; + +// Define the function to convert image to PDF +async function convertImageToPDF(imageFile) { + // Validate file type + if (imageFile.type !== 'image/png') { + throw new Error('Invalid file type. Only PNG files are supported.'); + } + + // Convert to PDF using jsPDF + const pdf = new jsPDF(); + pdf.addImage(imageFile, 'PNG', 0, 0); + + // Trigger download of the PDF + pdf.save('converted_image.pdf'); +} + +// Export the function for use in other files +export { convertImageToPDF }; \ No newline at end of file