In this post from the old Forum, @TIMAI2 shows us how we can create a PDF file with JavaScript using the jsPDF.js library.
Thank you TIM!
HOWTO: Create a PDF, offline, "within" AI2 using jsPDF and base64 extn by Juan Antonio
The code uses the jsPDF.js JavaScript library and an extension to work with Base64.
We will try to adapt the code without using the extension. [spoiler: currently not working]
I have used two methods, one with extension and the other without extension:
Method 1:
- Image file to Base64 via JavaScript.
- Convert content to PDF with jsPDF library.
- Get a PDF in string Base64.
- With extension KIO4_Base64 convert string Base64 to file pdf.
- Works!
Method 2:
- Image file to Base64 via JavaScript.
- Convert content to PDF with jsPDF library.
- Get a PDF in string Base64.
- Using the JavaScript atob command we decode the Base64.
- String to component File.Save
- No Works!
The problem is that atob doesn't decode the image well.