Coder Social home page Coder Social logo

api2pdf / api2pdf.tinymce Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 6.0 783 KB

TinyMCE plugin for saving HTML to PDF using the Api2Pdf API

License: MIT License

C# 57.08% CSS 3.12% JavaScript 11.87% ASP 0.96% HTML 6.88% PHP 20.10%
tinymce tinymce-plugin pdf-generation

api2pdf.tinymce's Introduction

api2pdf.tinymce

TinyMCE Plugin Code for Api2Pdf REST API

Api2Pdf.com is a REST API for instantly generating PDF documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), and images. The API also supports merge / concatenation of two or more PDFs. Api2Pdf is a wrapper for popular libraries such as wkhtmltopdf, Headless Chrome, and LibreOffice.

This plugin adds a Save to PDF functionality to TinyMCE. It will take the HTML contents of your editor, convert it to PDF, and request the web browser to download it.

The plugin will add a menu option to the toolbar to Save to PDF. It will also add an icon. image


Get Started with TinyMCE CDN

This sample HTML initializes TinyMCE via CDN and loads the latest Save-to-Pdf plugin via CDN. This example HTML replaces all textareas in a document to use TinyMCE loaded via CDN. Take a look at the init method, to make use of the save to pdf plugin you should take note of the following steps:

  1. Register savetoPdf in the external_plugins section
  2. If you wish to have a toolbar icon, register saveToPdf in your list of toolbar icons
  3. Finally you must set the handler. For more information on the handler see this section
<!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>

Get Started with TinyMCE Self Hosted

This sample HTML assumes TinyMCE is running from your local code base. It also assumes that you have downloaded the save-to-pdf plugin code from the repo (https://github.com/Api2Pdf/api2pdf.tinymce/tree/master/save-to-pdf/dist/save-to-pdf) and saved to your tinyMCE plugins folder (/tinymce/plugins/saveToPdf/plugin.js).

  1. Register savetoPdf in the external_plugins section
  2. If you wish to have a toolbar icon, register saveToPdf in your list of toolbar icons
  3. Finally you must set the handler. For more information on the handler see this section
<!DOCTYPE html>
<html>
<head>
    <script src="//scripts/tinymce.min.js"></script>
    <script>
        tinymce.init({
            selector: 'textarea',
            plugins: 'saveToPdf'                
            toolbar: 'saveToPdf',
            saveToPdfHandler: '/REPLACE-WITH-HANDLER-URL'
    });
    </script>
</head>
<body>
    <textarea>Testing saveToPdf</textarea>
</body>
</html>

Handlers and API Key

Whether you are using the CDN or self-hosting, you will need a server side handler to process the PDF generation request. This handler will take your incoming HTML and send it to Api2Pdf.com for processing.

  1. Create an account at portal.api2pdf.com to get your API key.
  2. Use the approproiate code example for your platform of choice PHP Handler or ASP.NET
  3. Place your Api2Pdf API key in the handler code
  4. Update the saveToPdfHandler configuration in your tinymce init function

PHP Handler and Sample Code

  1. Download the PHP Source code here: https://github.com/Api2Pdf/api2pdf.tinymce/tree/master/handlers/php api2pdf.php is the library code copied from https://github.com/Api2Pdf/api2pdf.php index.html assumes the sample was copied to /php/savetopdf.php

  2. In savetophp.php update the API key with the one you created at api2pdf.com

$a2p_client = new Api2PdfLibrary('YOURAPIKEY');
  1. Update the saveToPdfHandler configuration in your tinymce init function. See example

ASP.NET Handlers and Sample Code

  1. The ASP.NET sample code makes use of the Nuget Package API2PDF. Assuming you are building your own package you will first want to Install-Package Api2Pdf (https://github.com/Api2Pdf/api2pdf.dotnet)

  2. Copy the appropriate handler code

  1. Regardless of which handler you copy, you will want to update this line of code with the API key you created at api2pdf.com
var a2pClient = new Api2Pdf("YOURAPIKEY");
  1. Update the saveToPdfHandler configuration in your tinymce init function See example

api2pdf.tinymce's People

Contributors

apexdodge avatar bootleg224 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.