A simple Python wrapper for the PrinceXML PDF generation library
Prince XML installation guide.
$ pip install pyprince
Path to prince binary must be set using the prince_bin param:
importpyprincep=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:
importpyprinceoptions= {
"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 filesp.from_file(["./input1.html", "./input2.html"])
# Override optionsextra_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.importpyprincep=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.