Git Product home page Git Product logo

jspdf-json's Introduction

jsPDF-json

MIT licensed

jsPDF-json runs JSON schema through jsPDF to generate PDFs in client-side JavaScript.

Features

  • Maps JSON schema to jsPDF functions.
  • Inject data into your schema layouts for dynamic information.

Install

Since this library is dependent on jsPDF please ensure you have loaded that first. See how to install jsPDF here

Using npm:

npm install https://github.com/GeorgeD19/jsPDF-json.git

API

The jsPDF-json API translates directly to the jsPDF API for example:

var schema = `
[
    {
        "text": {
            "text": "Hello, World!",
            "x": 15,
            "y": 15
        }
    }
]`;
var doc = new jsPDF();
doc.JSON(schema);
doc.save('hello-world.pdf');

Is the same as:

var doc = new jsPDF();
doc.text("Hello, World!", 15, 15);
doc.save('hello-world.pdf');

Inject Data

So you can swap out variables from passed JSON which may be useful with using this library with JSON form libraries:

var schema = `[
    {
        "text": {
            "text": {nest.test},
            "x": 15,
            "y": 15
        }
    }
]`;
var data = `
{
    "nest": {
        "test": "Hello, World!"
    }
}
`;
var doc = new jsPDF();
doc.JSON(schema);
doc.save('hello-world.pdf');

Supported functions

  • addFont
  • addMetadata
  • addPage
  • autoPrint
  • addImage
  • circle
  • ellipse
  • getFontList
  • lines
  • lstext
  • rect
  • roundedRect
  • setDisplayMode
  • setDrawColor
  • setFillColor
  • setFont
  • setFontSize
  • setFontStyle
  • setLineCap
  • setLineJoin
  • setLineWidth
  • setPage
  • setTextColor
  • text
  • triangle

Limitations

  • addHTML is deprecated in jsPDF so will not be supported in this library
  • CapJoinStyles not implemented
  • setProperties not implemented
  • viewerPreferences not implemented

How to build

Pull the source by running the following command:

git clone https://github.com/GeorgeD19/jsPDF-json/

Prerequisites

You'll need to have Node.js and Gulp installed. New to Node.js or Gulp? Check out this writeup.

After installing Node.js you can install gulp globally by running the following command:

npm install -g gulp

To install all the necessary Node module dependencies, run the following command in the library directory:

npm install

Then to build run the following command:

gulp

The build distribution assets will be in the dist folder.

License (MIT)

Copyright (c) 2018 GeorgeD19, https://github.com/GeorgeD19/jsPDF-json

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ØOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jspdf-json's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pronoiastudios

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.