Pipeline publishing: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
apt-get install pdftk inkscape | apt-get install pdftk inkscape | ||
The svg template: | |||
<source lang="python"> | <source lang="python"> | ||
def dump (f, text, page): | |||
def dump ( | f.write("""<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<!-- Created with Inkscape (http://www.inkscape.org/) --> | <!-- Created with Inkscape (http://www.inkscape.org/) --> | ||
Line 15: | Line 16: | ||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | ||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | ||
width=" | width="524.40942" | ||
height=" | height="744.09448" | ||
id="svg2" | id="svg2" | ||
version="1.1" | version="1.1" | ||
inkscape:version="0. | inkscape:version="0.47 r22583" | ||
sodipodi:docname="New document 1"> | sodipodi:docname="New document 1"> | ||
<defs | <defs | ||
id="defs4" /> | id="defs4"> | ||
<inkscape:perspective | |||
sodipodi:type="inkscape:persp3d" | |||
inkscape:vp_x="0 : 526.18109 : 1" | |||
inkscape:vp_y="0 : 1000 : 0" | |||
inkscape:vp_z="744.09448 : 526.18109 : 1" | |||
inkscape:persp3d-origin="372.04724 : 350.78739 : 1" | |||
id="perspective10" /> | |||
</defs> | |||
<sodipodi:namedview | <sodipodi:namedview | ||
id="base" | id="base" | ||
Line 30: | Line 39: | ||
inkscape:pageopacity="0.0" | inkscape:pageopacity="0.0" | ||
inkscape:pageshadow="2" | inkscape:pageshadow="2" | ||
inkscape:zoom="0. | inkscape:zoom="0.61742627" | ||
inkscape:cx=" | inkscape:cx="80.403821" | ||
inkscape:cy=" | inkscape:cy="217.57273" | ||
inkscape:document-units="px" | inkscape:document-units="px" | ||
inkscape:current-layer="layer1" | inkscape:current-layer="layer1" | ||
showgrid="false" | showgrid="false" | ||
inkscape:window-width=" | inkscape:window-width="1511" | ||
inkscape:window-height=" | inkscape:window-height="910" | ||
inkscape:window-x="0" | inkscape:window-x="0" | ||
inkscape:window-y=" | inkscape:window-y="25" | ||
inkscape:window-maximized=" | inkscape:window-maximized="0" /> | ||
<metadata | <metadata | ||
id="metadata7"> | id="metadata7"> | ||
Line 56: | Line 65: | ||
inkscape:label="Layer 1" | inkscape:label="Layer 1" | ||
inkscape:groupmode="layer" | inkscape:groupmode="layer" | ||
id="layer1"> | id="layer1" | ||
transform="translate(0,-308.26769)"> | |||
<flowRoot | <flowRoot | ||
xml:space="preserve" | xml:space="preserve" | ||
id=" | id="flowRoot2816" | ||
style=" | style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" | ||
id=" | transform="translate(0,308.26769)"><flowRegion | ||
id=" | id="flowRegion2818"><rect | ||
width=" | id="rect2820" | ||
height=" | width="445.39731" | ||
x=" | height="553.91229" | ||
y=" | x="34.012157" | ||
id=" | y="83.286842" /></flowRegion><flowPara | ||
id="flowPara2822" /></flowRoot> <flowRoot | |||
xml:space="preserve" | |||
id="flowRoot2824" | |||
style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" | |||
transform="translate(1.3658447,425.26064)"><flowRegion | |||
id="flowRegion2826"><rect | |||
id="rect2828" | |||
width="453.49545" | |||
height="524.75903" | |||
x="34.012157" | |||
y="62.231693" /></flowRegion><flowPara | |||
id="flowPara2830" | |||
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Georgia;-inkscape-font-specification:Georgia">""") | |||
f.write(text) | |||
f.write("""</flowPara></flowRoot> <flowRoot | |||
xml:space="preserve" | xml:space="preserve" | ||
id=" | id="flowRoot2832" | ||
style="font-size:40px;font-style:normal;font-weight:normal | style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" | ||
transform="translate( | transform="translate(20.931274,308.26769)"><flowRegion | ||
id=" | id="flowRegion2834"><rect | ||
id=" | id="rect2836" | ||
width=" | width="119.85236" | ||
height=" | height="69.643944" | ||
x=" | x="181.39818" | ||
y=" | y="651.77576" /></flowRegion><flowPara | ||
id=" | id="flowPara2838" | ||
style="font-size:28px;text-align:center;text-anchor:middle;font-family:Georgia;-inkscape-font-specification:Georgia">""") | |||
f.write(str(page)) | |||
f.write("""</flowPara></flowRoot> </g> | |||
</svg>""") | |||
</source> | |||
The publishing part | |||
<source lang="python"> | |||
import sys, os | import sys, os | ||
import codecs | import codecs |
Revision as of 15:48, 21 June 2011
apt-get install pdftk inkscape
The svg template:
def dump (f, text, page):
f.write("""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="524.40942"
height="744.09448"
id="svg2"
version="1.1"
inkscape:version="0.47 r22583"
sodipodi:docname="New document 1">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.61742627"
inkscape:cx="80.403821"
inkscape:cy="217.57273"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1511"
inkscape:window-height="910"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-308.26769)">
<flowRoot
xml:space="preserve"
id="flowRoot2816"
style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
transform="translate(0,308.26769)"><flowRegion
id="flowRegion2818"><rect
id="rect2820"
width="445.39731"
height="553.91229"
x="34.012157"
y="83.286842" /></flowRegion><flowPara
id="flowPara2822" /></flowRoot> <flowRoot
xml:space="preserve"
id="flowRoot2824"
style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
transform="translate(1.3658447,425.26064)"><flowRegion
id="flowRegion2826"><rect
id="rect2828"
width="453.49545"
height="524.75903"
x="34.012157"
y="62.231693" /></flowRegion><flowPara
id="flowPara2830"
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;text-anchor:middle;font-family:Georgia;-inkscape-font-specification:Georgia">""")
f.write(text)
f.write("""</flowPara></flowRoot> <flowRoot
xml:space="preserve"
id="flowRoot2832"
style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
transform="translate(20.931274,308.26769)"><flowRegion
id="flowRegion2834"><rect
id="rect2836"
width="119.85236"
height="69.643944"
x="181.39818"
y="651.77576" /></flowRegion><flowPara
id="flowPara2838"
style="font-size:28px;text-align:center;text-anchor:middle;font-family:Georgia;-inkscape-font-specification:Georgia">""")
f.write(str(page))
f.write("""</flowPara></flowRoot> </g>
</svg>""")
The publishing part
import sys, os
import codecs
f = codecs.open("input.txt", "r", "utf-8")
lines = f.read().splitlines()
# strip blank lines
lines = [x for x in lines if x.strip()]
import random
for c in range(10):
text = random.choice(lines)
svgname = "out%04d.svg" % c
pdfname = "out%04d.pdf" % c
print svgname
f = codecs.open(svgname, "w", "utf-8")
dump(f)
f.close()
os.system("inkscape %s --export-pdf=%s" % (svgname, pdfname))
os.system("pdftk out*.pdf output book.pdf")