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