Blog
CKEditor Save to PDF Plugin

Intro
CKEditor4 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="https://cdn.ckeditor.com/4.10.0/standard/ckeditor.js"></script> | |
| <script> | |
| CKEDITOR.plugins.addExternal( 'save-to-pdf', 'https://rawgit.com/Api2Pdf/api2pdf.ckeditor4/master/plugins/save-to-pdf/', 'plugin.js' ); | |
| </script> | |
| </head> | |
| <body> | |
| <textarea name="editor1"></textarea> | |
| <script> | |
| CKEDITOR.replace( 'editor1', | |
| { | |
| extraPlugins: 'save-to-pdf', | |
| pdfHandler: '/api2pdf-lib/savetopdf.php' | |
| } ); | |
| </script> | |
| </body> | |
| </html> |
The above HTML code loads CKEditor 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 CKEditor.replace
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!