@cepharum/pdf-maker

    0.1.2-alpha.1 • Public • Published

    PDF Maker

    converting Markdown to PDF

    License

    MIT

    About

    This tool is combining markdown-it with pdfmake using Hitchy to expose a markdown-to-PDF converter via REST-like API.

    API

    When exposing this service at http://127.0.0.1:3000, sending a POST request to

    http://127.0.0.1:3000/print/test.pdf

    is generating PDF document named test.pdf. The resulting document isn't stored on server, but instantly sent to requesting client in response.

    The request needs to provide content to be rendered. Provide information in JSON-encoded request body describing with property content providing content of resulting document as Markdown-encoded string. In addition, a second property named theme is optionally providing styling information mostly forwarded to pdfmake. See the following example:

    {
        "content": "# Title\n\nThis is some Markdown text including:\n\n* a list\n* with two items.",
        "theme": {
             "defaultStyle": {
                 "fontSize": 11
             },
             "pageSize": "A4",
             "styles": {
                 "p": {
                     "marginTop": 11
                 },
                 "ul": {
                     "marginTop": 11
                 },
                 "ol": {
                     "marginTop": 11
                 },
                 "h1": {
                     "marginTop": 36,
                     "fontSize": 36
                 },
                 "h2": {
                     "fontSize": 24,
                     "marginTop": 10
                 },
                 "h3": {
                     "fontSize": 20,
                     "bold": true,
                     "italics": true,
                     "marginTop": 10
                 }
             }
        }
    }

    How it works

    By combining markdown-it with pdfmake, this application is parsing some provided markdown text converting resulting hierarchy of tokens into content definition suitable for use with pdfmake. In addition, an extended engine is processing styling definitions in provided theme injecting pdfmake-compatible styling definitions as well as adjusting resulting content definitions.

    Demonstration

    The service is available as a docker container.

    docker run --rm -p 3000:3000  cepharum/pdf-maker
    

    This command is running pdf-maker. When started, open http://127.0.0.1:3000 in your browser. This will load a simple page providing editor for generating PDF documents from markdown content and JSON styling.

    Keywords

    none

    Install

    npm i @cepharum/pdf-maker

    DownloadsWeekly Downloads

    4

    Version

    0.1.2-alpha.1

    License

    MIT

    Unpacked Size

    47.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • simon.friedo
    • soletan