Skip to content

sufio/python-pyprince

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-pyprince

A simple Python wrapper for the PrinceXML PDF generation library

Installation

Prince XML

Prince XML installation guide.

python-pyprince

$ pip install pyprince

Usage

Path to prince binary must be set using the prince_bin param:

import pyprince

p = pyprince.Prince(prince_bin='/usr/local/bin/prince')

You can specify all Prince XML options. You can drop '--' in option name. If option is without value use None or False:

import pyprince

options = {
    "page-size": "A3",
    "output": "./output.pdf",
    "style": "./styles.css"
}

p = pyprince.Prince(prince_bin='/usr/local/bin/prince', options=options)

p.from_string("Hello")
p.from_file("./input.html")

# pass a list with multiple files
p.from_file(["./input1.html", "./input2.html"])

# Override options

extra_options = {
    "page-size": "A4",
    "debug": None
}

p.from_string("Hello", extra_options)
p.from_file("./input.html", extra_options)

You can read it to a variable:

# From Prince documentation:
# The output file name can be specified on the command line using
# the --output command line option.
# An output filename consisting of a single hyphen "-" will
# cause pyprince to write to the standard output stream.

import pyprince

p = pyprince.Prince(prince_bin='/usr/local/bin/prince')

options = {"output": "-"}
pdf = p.from_file("./input.html", options)

This library is maintained by Sufio - Professional Invoices.

About

A simple Python wrapper for the PrinceXML PDF generation library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •