simple-fpdf


Namesimple-fpdf JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/alexander-schillemans/simple-fpdf
SummarySimple FPDF
upload_time2022-12-07 11:58:47
maintainer
docs_urlNone
authorAlexander Schillemans
requires_python
licenseGPL-3.0-or-later
keywords pdf fpdf simple_fpdf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Simple FPDF
A simplified version of the FPDF package.

## Aim of this package
This package aims to make it easier to generate a PDF, without concerning yourself with the difficulties of keeping track of the (x,y) position inside the document.

A simple row-column system is used to generate a PDF and insert text.
Since this extends the FPDF package, all the FPDF functionalities are still included.

# Getting started

### Install

Install with pip.

```python
pip install simple-fpdf
```

### Import

Import the package and SimpleFPDF.

```python
from simple_fpdf import SimpleFPDF
```

# How to use

## Initialize SimpleFPDF

SimpleFPDF is initialized the same as a normal FPDF. You can also use the `width` and `height` parameters. If no `format`, `width` or `height` is specified, A4 will be used.

```python
pdf = SimpleFPDF(orientation='P', unit='mm', format="A4")
pdf = SimpleFPDF(orientation='P', unit='mm', width=210, height=297)
```

## Defining the rows and columns

SimpleFPDF makes use of a simple row-column system where all the rows on the page have an equal height.
Before adding a page, you need to define how many rows a page will have, and how many columns these rows will contain.

```python
page_1_rows = [
    { 'columns' : 1 }, # row 1, has one column
    { 'columns' : 1 }, # row 2, has one column
    { 'columns' : 2 }, # row 3, has two columns
    { 'columns' : 3 } # row 4, has three columns
]
```

## Adding a page

Add a page using the known `.add_page()` method. This method expects a new parameter: `rows`.
Rows need to be an array with the row definitions as specified above.

```python
pdf.add_page(rows=page_1_rows)
```

## Writing text

Once you have a page and their rows and columns, you can simply start writing text to it using `.write_text()`. This function takes three required parameters: `row`, `column` and `txt`.
Optionally, you can also specify the `page` by giving its number. If no page is given, the current page is used.

```python
pdf.write_text(txt='This is my heading', row=1)
pdf.write_text(txt='This is my second row', row=2)
pdf.write_text(txt='This is my thirth row, first column', row=3, column=1)
pdf.write_text(txt='This is my thirth row, second column', row=3, column=2)
pdf.write_text(txt='This is my fourth row, first column', row=4, column=1)
pdf.write_text(txt='This is my fourth row, second column', row=4, column=2)
pdf.write_text(txt='This is my fourth row, thirth column', row=4, column=3)
```

## Output

Generate the pdf using the `.output()` method.

```python
pdf.output('my_pdf.pdf')
```

## Advanced settings

Since SimpleFPDF aims to be as simple as possible, not much customisation is possible.
There are a few settings you can use.

### top-margin

You can specify the `top-margin` for a row. This will add a margin to the top of a row, using the unit specified at creation.

```python
rows = [
    { 'columns' : 1, 'top-margin' : 30 }, # row 1, has one column and a top-margin of 30mm
    { 'columns' : 1 }, # row 2, has one column
    { 'columns' : 2, 'top-margin' }, # row 3, has two columns and a top-margin of 15mm
    { 'columns' : 3 } # row 4, has three columns
]
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alexander-schillemans/simple-fpdf",
    "name": "simple-fpdf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pdf,fpdf,simple_fpdf",
    "author": "Alexander Schillemans",
    "author_email": "alexander.schillemans@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/58/3e/42e49b9c4824cd2090264f22626eb353d3527e3fc35459220edb9f230d3f/simple-fpdf-0.1.0.tar.gz",
    "platform": null,
    "description": "# Simple FPDF\r\nA simplified version of the FPDF package.\r\n\r\n## Aim of this package\r\nThis package aims to make it easier to generate a PDF, without concerning yourself with the difficulties of keeping track of the (x,y) position inside the document.\r\n\r\nA simple row-column system is used to generate a PDF and insert text.\r\nSince this extends the FPDF package, all the FPDF functionalities are still included.\r\n\r\n# Getting started\r\n\r\n### Install\r\n\r\nInstall with pip.\r\n\r\n```python\r\npip install simple-fpdf\r\n```\r\n\r\n### Import\r\n\r\nImport the package and SimpleFPDF.\r\n\r\n```python\r\nfrom simple_fpdf import SimpleFPDF\r\n```\r\n\r\n# How to use\r\n\r\n## Initialize SimpleFPDF\r\n\r\nSimpleFPDF is initialized the same as a normal FPDF. You can also use the `width` and `height` parameters. If no `format`, `width` or `height` is specified, A4 will be used.\r\n\r\n```python\r\npdf = SimpleFPDF(orientation='P', unit='mm', format=\"A4\")\r\npdf = SimpleFPDF(orientation='P', unit='mm', width=210, height=297)\r\n```\r\n\r\n## Defining the rows and columns\r\n\r\nSimpleFPDF makes use of a simple row-column system where all the rows on the page have an equal height.\r\nBefore adding a page, you need to define how many rows a page will have, and how many columns these rows will contain.\r\n\r\n```python\r\npage_1_rows = [\r\n    { 'columns' : 1 }, # row 1, has one column\r\n    { 'columns' : 1 }, # row 2, has one column\r\n    { 'columns' : 2 }, # row 3, has two columns\r\n    { 'columns' : 3 } # row 4, has three columns\r\n]\r\n```\r\n\r\n## Adding a page\r\n\r\nAdd a page using the known `.add_page()` method. This method expects a new parameter: `rows`.\r\nRows need to be an array with the row definitions as specified above.\r\n\r\n```python\r\npdf.add_page(rows=page_1_rows)\r\n```\r\n\r\n## Writing text\r\n\r\nOnce you have a page and their rows and columns, you can simply start writing text to it using `.write_text()`. This function takes three required parameters: `row`, `column` and `txt`.\r\nOptionally, you can also specify the `page` by giving its number. If no page is given, the current page is used.\r\n\r\n```python\r\npdf.write_text(txt='This is my heading', row=1)\r\npdf.write_text(txt='This is my second row', row=2)\r\npdf.write_text(txt='This is my thirth row, first column', row=3, column=1)\r\npdf.write_text(txt='This is my thirth row, second column', row=3, column=2)\r\npdf.write_text(txt='This is my fourth row, first column', row=4, column=1)\r\npdf.write_text(txt='This is my fourth row, second column', row=4, column=2)\r\npdf.write_text(txt='This is my fourth row, thirth column', row=4, column=3)\r\n```\r\n\r\n## Output\r\n\r\nGenerate the pdf using the `.output()` method.\r\n\r\n```python\r\npdf.output('my_pdf.pdf')\r\n```\r\n\r\n## Advanced settings\r\n\r\nSince SimpleFPDF aims to be as simple as possible, not much customisation is possible.\r\nThere are a few settings you can use.\r\n\r\n### top-margin\r\n\r\nYou can specify the `top-margin` for a row. This will add a margin to the top of a row, using the unit specified at creation.\r\n\r\n```python\r\nrows = [\r\n    { 'columns' : 1, 'top-margin' : 30 }, # row 1, has one column and a top-margin of 30mm\r\n    { 'columns' : 1 }, # row 2, has one column\r\n    { 'columns' : 2, 'top-margin' }, # row 3, has two columns and a top-margin of 15mm\r\n    { 'columns' : 3 } # row 4, has three columns\r\n]\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "Simple FPDF",
    "version": "0.1.0",
    "split_keywords": [
        "pdf",
        "fpdf",
        "simple_fpdf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "447cd41fb32b5c448f0483510ced7e7a",
                "sha256": "613b499d0b4c601b9c7c45b052736c9fbf2cc03a51a95efc6c96c598398815a0"
            },
            "downloads": -1,
            "filename": "simple-fpdf-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "447cd41fb32b5c448f0483510ced7e7a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16040,
            "upload_time": "2022-12-07T11:58:47",
            "upload_time_iso_8601": "2022-12-07T11:58:47.635440Z",
            "url": "https://files.pythonhosted.org/packages/58/3e/42e49b9c4824cd2090264f22626eb353d3527e3fc35459220edb9f230d3f/simple-fpdf-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-07 11:58:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "alexander-schillemans",
    "github_project": "simple-fpdf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "simple-fpdf"
}
        
Elapsed time: 0.02914s