The first step is to acquire an API key from portal.api2pdf.com. Once you grab your API key, you are almost set. The following jQuery ajax call can be used to call the API. Your only task is to replace the apikey variable ‘YOUR-API-KEY’ with the apikey you pulled from portal.api2pdf.com.
You can call this function with your raw HTML. Feel free to modify this function to call a URL and use the URL endpoint instead, or convert word files to PDFs with our LibreOffice endpoint. See our full documentation for the REST API here.
View a full working source code of HTML here: https://gist.github.com/apexdodge/556badd8b4fbf71d3cc566800b52b012
View a JS fiddle demo version of the above code here: https://jsfiddle.net/apexdodge/xpvt214o/723551/
Just be sure to replace the apikey with your own in both the HTML and JS Fiddle examples.
The reason most people use Api2Pdf from the server side is so that they do not expose their Api2Pdf apikey. If someone has your api key, they can use the key to generate their own PDFs with your own account. Therefore we always recommend doing server-side generation, leaving this client-side approach as a last resort, and only if you really trust your user base.
Comments are closed.