Blog
tinyMCE Save to PDF Plugin
Intro
TinyMCE is a battle tested and widely used WYSIWYG html editor. In this post we will discuss how to use our open source plugin for saving the document to PDF.
Example Code + Demo
Feel free to check out our github page for detailed step by step documentation.
HTML Code
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script> | |
<script> | |
tinymce.init({ | |
selector: 'textarea', | |
external_plugins: | |
{ | |
'saveToPdf': 'https://cdn.rawgit.com/Api2Pdf/api2pdf.tinymce/master/save-to-pdf/dist/save-to-pdf/plugin.js' | |
}, | |
toolbar: 'saveToPdf', | |
saveToPdfHandler: '/REPLACE-WITH-HANDLER-URL' | |
}); | |
</script> | |
</head> | |
<body> | |
<textarea>Testing saveToPdf</textarea> | |
</body> | |
</html> |
The above HTML code loads tinyMCE over the CDN, it also uses rawgit to quickly generate a CDN link we can use for our plugin javascript.
Important Points
1 – You’ll notice most of the code is loaded via CDN, however we have a saveToPdfHandler property that needs to be set in tinymce.init
2 – Pick your Handler of Choice, we have sample code for PHP and for ASP.NET, let’s use our ASP.NET classic handler (ASHX) for simplicity
3 – Simply swap out YOURAPIKEY with one you can grab from the api2pdf portal
4 – Putting all of this together you get a result that looks like the demo below:
Thanks for visiting our site. If you are eager to start generating PDFs right away with just a few lines of code, grab your API key and check out our docs!