jsPDF supports all kinds of inputs from text, shapes, images, to complete HTML but for this demo we will just focus on text and I will add one image for fun. The image needs to be in Data URL format and you can do that programmatically via CANVAS.toDataURL() method or an online tool like dataurlmaker. I will be using a smaller version of the image for this post in my first slide with the title “Create Slideshows Programatically.”
Here is the code that automates the pdf creation
Since the SlideShare API does not allow CORS, we need to either proxy the API request through server side or just use cURL. If you looked at the source code of the link above you will see I commented out the doc.save() call as it downloads a pdf to the filesystem. If you uncomment it, you will have a pdf file ready to send over to SlideShare and you can even schedule this via a cron job.
Once you grabbed an API key, you can make a POST call via cURL with a PHP script. You need the key whitelisted and there are some interesting Authentication requirements (using timestamps and SHA1 hashes) but the following PHP code with cURL worked well: