Download the PHP package ratiw/jsonpdf without Composer

On this page you can find all versions of the php package ratiw/jsonpdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package jsonpdf

JsonPDF is a wrapper class for FPDF to allow creating PDF document from JSON data.

Install using Composer

Just add the requirement to you composer.json file.

{
    "require": {
        "ratiw/jsonpdf": "~1.0"
    }
}

Example

See more examples in the examples direcoty.


JSON data structure

{
    "header":   [..array of object..],
    "footer":   [..array of object..],
    "body":     [..array of object..],
    "settings": [
        "title":    "Document Title",
        "author":   "Author name",
        "subject":  "Subject",
        "creator":  "Generator name",
        "keywords": "list of keywords here",
        "defaultFont": [
            "name": "FontName",
            "size":  16
        ]
    ],
    "fonts":    [..array of font to be added..],
    "data":     [..array of data..],
    "tables":   [..table definition..]
}
Sections Description
header Contains array of objects to be rendered in the header section on every pages of the PDF document.
footer Contains array of objects to be rendered in the footer section on every pages of the PDF document.
body Contains array of objects to be rendered in the body section of the PDF docuemnt.
settings Defines the properties and the default settings of the PDF document.
fonts List of fonts to be added before rendering the PDF document. These fonts will be embedded to the document by default.
data Array of data to be binded to the text object while rendering the PDF document.
tables Defines each table properties. These table will be reference by table, table-header, table-body objects.

Objects

There are 5 object types in JsonPDF. Each doing a specific task to render PDF document.

Every objects share some common properties like the draw color, fill color (background color), x-y position, etc.

The following object types are available:

Common Object Properties

The following properties are common to all objects, which mean they can be set on any object. They may or may not affect the rendering of the object depending on whether that object uses that property or not.

properties

render-as Property

JsonPDF can be rendered in three different mode. Render only those objects marked as form (RENDER_FORM_ONLY), render only those objects marked as data (RENDER_DATA_ONLY), or render both form and data ('RENDER_ALL`).

The rendered document can be shown as a blank form (RENDER_FORM_ONLY), or can be shown raw data (RENDER_DATA_ONLY) to printed on the pre-made paper form, or can be shown both (RENDER_ALL) to be printed on plain paper.

By default if the render-as property of the object is not defined, the object will be regarded as RENDER_ALL. That means it will get rendered both as part of a form and a data.

Text Object

The text object uses to display text at the specified position. Data can be bound to the text object by enclosing the data name in curly braces {} embedding in the text property of the text object.

The following example shows the username data embedded in the text property. This username will be replaced by the actual data provided in the data section of the JSON.

"body": [
    {
        "type": "text",
        "x": 10,
        "y": 20,
        "text": "Hello, {username}. How are you today!",
        "text-color": "255,125,125"
    }
],
"data": [
    "username": "Rati"
]

Additional properties

Line Object

The line object uses to draw a line at the given position specified by x1, y1, x2, y2.

properties

Rect Object

The rect object uses to draw a rectangle on the document using the specified x, y, width, height properties.

properties

Image Object

The image object uses to draw the given image on the document at the speicifed location, width and height.

properties

Table, Table Header, Table Body Objects

The table object is used to draw a data table on the document. The table properties must be defined in the tables section and the data must be present in the data section of the JSON.

table object will render the complete table with the table header and body.

table-header object will render only the header part of the given table.

table-body object will render only the body part of the given table.

properties


Settings

This section is used to set various properties for the PDF document.

"settings": {
    "title": "Test PDF Document",
    "author": "Rati Wannapanop",
    "creator": "JsonPDF"
}

properties


Defining Fonts

You can add custom fonts to be used in your PDF document in this section by providing the array of fontname, fontstyle, and fontfile.

In order to use your own custom fonts, you must creating the fontfile using FPDF's MakeFont function.

See more information on this at FPDF website.

"fonts": [
    ["THSarabun", "", "THSarabun.php"],
    ["THSarabun", "B", "THSarabun Bold.php"],
    ["THSarabun", "I", "THSarabun Italic.php"],
    ["THSarabun", "BI", "THSarabun Bold Italic.php"]
]

Data Binding

You define data for the variables in this data section. Variable name is enclosed in the curly braces, e.g. {name}.

Variables are usually embedded in the text property of the Text object.

"body": [
    {
        'type': 'text',
        'text': 'Hello, {name}! Today is {date}.'
    }
],
//
// ....
//
"data": {
    "name": "Rati Wannapanop",
    "date": "17/11/2556",
    "table1": [
        ["country": "Austria", "capital": "Vienna", "area": "83,859", "pop": "8,075"],
        ["country": "Belgium", "capital": "Brussels", "area": "30,518", "pop": "10,192"],
        ["country": "Denmark", "capital": "Copenhagen", "area": "43,094", "pop": "5,295"]
    ]
}

Tables Definition

You can define tables structure in this section. Each table definition consists of 3 properties: columns, data, and style.

rows-per-page property (optional) specifies the number of rows to be displayed per page. Blank rows will be displayed if necessary.

columns property defines each column characteristic for the given table. See Table Column below.

data property specifies which key in the data section should be used for data rendering inside the given table.

style property defines how the given table should be rendered. The style properties is optional and if omitted default value will be used. See Table Style below.

"tables": [
    ["world_info_table": {
        "rows-per-page": 10,
        "columns": [
            {
                "name": "country",
                "width": 45,
                "title": "Country",
                "title-align": "L",
                "data-align": "L"
            },
            ...
            ...
            {
                "name": "pop",
                "width": 50,
                "title": "Pop. (thousands)",
                "title-align": "C",
                "data-align": "R"
            }
        ],
        "data": "world_info_data",
        "style": {
            "border-color": "50,55,200",
            "border": "LR",
            "title-row": {
                "height": 8,
                "text-color": "200,100,50",
                "fill-color": "100,50,50"
            },
            "data-row": {
                "height": 8,
                "text-color": "0,0,0",
                "fill-color": "224,235,255",
                "striped": true,
            }
        }
    }],
    ["second_table": {
        ...
        ...
    }]
],

Table Column

"columns": [
    {"name": "country", "width": 45, "title": "Country", "title-align": "L", "data-align": "L"},
    {"name": "capital", "width": 40, "title": "Capital", "data-align": "L"},
    {"name": "area", "width": 45, "title": "Area (sq km)", "title-align": "C", "data-align": "R"},
    {"name": "pop", "width": 50, "title": "Pop. (thousands)", "title-align": "C", "data-align": "R"}
]

Table Style The table style property allow the user to define how the table should looks.

"style": {
    "border-color": "50,55,200",
    "title-row": {
        "text-color": "200,100,50",
        "fill-color": "100,50,50",
    },
    "data-row": {
        "height": 8,
        "text-color": "0,0,0",
        "fill-color": "224,235,255",
        "striped": true
    }
}

Utility functions


All versions of jsonpdf with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ratiw/jsonpdf contains the following files

Loading the files please wait ....