1. Products
  2.   PDF
  3.   Python
  4.   borb
 
  

Create PDF Files, Add Charts & Barcodes via Python Library

Free Python API capable of creating, editing and reading PDF Files, Insert & Modify Charts, Merge, Split or Rotate PDF Files via Python Library.

borb is a very powerful open source Python library that fully supports generating, reading, and manipulating PDF documents inside Python applications. Handling PDF documents is a very challenging task. The borb library is very user-friendly and time-saving which makes the developer's job easy. You don’t need to have detailed knowledge of the inner working of PDF file format. It allows users to specify the page layout while it handles the specific details of laying out the text. It can be used to create fillable forms, invoices with attached data files, and multiple-column document layouts.

borb has included support for numerous features related to PDF file creation and management, such as reading PDF documents, extracting meta-information, extracting text from PDF files, extracting images from PDF, inserting text to PDF, changing images inside PDF documents, adding annotations to PDF, insert tables to PDF, merging and splitting existing PDF documents, add lists to PDF, PageLayout manager usage, transforming PDF pages, and many more. The library is well documented and When it comes to ease of use, borb is the greatest in class.

Previous Next

Getting Started with borb

borb doesn’t come as a part of the Python Standard Library, so you will need to install it yourself. The preferred way to do so is to use pip.

Install borb  via pip

 pip install borb 

It is also possible to install it manually; download the latest release files directly from GitHub repository.

Generate PDF Files from Scratch via Python

The open source borb library let’s Python developers create PDF documents from the scratch without any external dependencies. It supports creating and examining the contents inside a PDF file with ease. Once the PDF document is created you can insert text, shapes and images, apply formatting to text, set font and font color, set page layout, add new pages, add forms, and so on. The Library also provides complete support for manipulate existing PDF documents.

Create PDF Documents & Add Page via Python

from borb.pdf import Document
from borb.pdf import Page


def main():
    # create Document
    doc: Document = Document()

    # create Page
    page: Page = Page()

    # add Page to Document
    doc.add_page(page)


if __name__ == "__main__":
    main() 

Insert & Manage Barcodes in PDF via Python API

If you want to add interactivity to your documents, Barcodes are can help you out in that regard. It helps developers in linking the printed document to an online resource with ease. The open source borb library provides complete functionality for adding various types of Barcodes inside PDF pages such as QR-code, CODE_128, CODE_39, EAN, EAN_13, GS_1, ISBN, and many more. You can also easily modify various properties, like fill color, width, height, stroke color, and so on.

Add Barcode to a PDF Page via Python API

def main():
    # create Document
    doc: Document = Document()

    # create Page
    page: Page = Page()

    # add Page to Document
    doc.add_page(page)

    # set a PageLayout
    layout: PageLayout = SingleColumnLayout(page)

    # add a Paragraph
    layout.add(
        Barcode(
            "1234567896120",
            width=Decimal(128),
            height=Decimal(128),
            type=BarcodeType.EAN_14,
        )
    )

    # store
    with open("output.pdf", "wb") as pdf_file_handle:
        PDF.dumps(pdf_file_handle, doc)


if __name__ == "__main__":
    main()

Insert & Modify Charts in PDFs via Python Library

Charts are always very useful for presenting data graphically as it is very easy for users to comprehend data faster in a form of picture rather than from text. The borb library provides capability for programmatically adding charts inside PDF documents with just a couple of lines of Python code. You can also modify the contents of a charts and customize according to your own needs.

Merge, Split & Rotate PDF Documents via Python Library

The open source borb library gives software programmers the power process their PDF documents in numerous ways. It is often needed to combine multiple PDF documents or different pages of PDF documents to create a new document from it or split a large PDF documents to into smaller ones. They can easily open and access existing PDF files, split, merge or combine it with just a couple of lines of Python code. More, it is also very easy to rotate documents inside Python applications.

 

How to Merge PDF Documents via Python API

def main():

    # open doc_001
    doc_001: typing.Optional[Document] = Document()
    with open("output_001.pdf", "rb") as pdf_file_handle:
        doc_001 = PDF.loads(pdf_file_handle)

    # open doc_002
    doc_002: typing.Optional[Document] = Document()
    with open("output_002.pdf", "rb") as pdf_file_handle:
        doc_002 = PDF.loads(pdf_file_handle)

    # merge
    doc_001.add_document(doc_002)

    # write
    with open("output_003.pdf", "wb") as pdf_file_handle:
        PDF.dumps(pdf_file_handle, doc_001)


if __name__ == "__main__":
    main()
 English