-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversion script and command line call
- Loading branch information
0 parents
commit 8e984c5
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
./xml2pdf.py --xml ../files/test.xml --xsl ../stylesheets/jats-html.xsl -o ../files/testpy.pdf --css ../stylesheets/jats-preview.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python | ||
|
||
import sys, getopt, logging | ||
from weasyprint import HTML, CSS | ||
from lxml import etree | ||
|
||
def usage(): | ||
sys.stderr.write("./xml2pdf.py --xml <xml-file> --xsl <xsl-file> -o <pdf-output> [--css <stylesheet>]") | ||
|
||
options, rest = getopt.getopt(sys.argv[1:], "o:", ["xml=", "xsl=", "output=","css="]) | ||
|
||
out_fn = None | ||
xml_fn = None | ||
xsl_fn = None | ||
css_fn = None | ||
|
||
for opt, arg in options: | ||
if opt in ("-o", "--output"): | ||
out_fn = arg | ||
elif opt == "--xml": | ||
xml_fn = arg | ||
elif opt == "--xsl": | ||
xsl_fn = arg | ||
elif opt == "--css": | ||
css_fn = arg | ||
else: | ||
sys.stderr.write("Unknown option %s"%opt) | ||
|
||
if not (out_fn and xml_fn and xsl_fn): | ||
usage() | ||
|
||
xsl = etree.parse(xsl_fn) | ||
transformer = etree.XSLT(xsl) | ||
|
||
xml = etree.parse(xml_fn) | ||
|
||
logging.info | ||
html = transformer(xml) | ||
|
||
if css_fn: | ||
css = [CSS(css_fn)] | ||
else: | ||
css = None | ||
|
||
HTML(tree=html).write_pdf(out_fn, css) |