Pipeline publishing: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 1: Line 1:
apt-get install pdftk inkscape
<source lang="python">
<source lang="python">



Revision as of 12:37, 21 June 2011

apt-get install pdftk inkscape
def dump (out):
    out.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="744.09448819"
   height="1052.3622047"
   id="svg2"
   version="1.1"
   inkscape:version="0.48.1 r9760"
   sodipodi:docname="New document 1">
  <defs
     id="defs4" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="0.35"
     inkscape:cx="375"
     inkscape:cy="520"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="1024"
     inkscape:window-height="744"
     inkscape:window-x="0"
     inkscape:window-y="24"
     inkscape:window-maximized="1" />
  <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">
    <flowRoot
       xml:space="preserve"
       id="flowRoot2985"
       style="fill:black;stroke:none;stroke-opacity:1;stroke-width:1px;stroke-linejoin:miter;stroke-linecap:butt;fill-opacity:1;font-family:Sans;font-style:normal;font-weight:normal;font-size:40px;line-height:125%;letter-spacing:0px;word-spacing:0px"><flowRegion
         id="flowRegion2987"><rect
           id="rect2989"
           width="588.57141"
           height="525.71429"
           x="71.428574"
           y="92.362183" /></flowRegion><flowPara
         id="flowPara2991"></flowPara></flowRoot>    <flowRoot
       xml:space="preserve"
       id="flowRoot2993"
       style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
       transform="translate(-11.428571,-62.857143)"><flowRegion
         id="flowRegion2995"><rect
           id="rect2997"
           width="585.71429"
           height="831.42859"
           x="97.14286"
           y="158.07646" /></flowRegion><flowPara
         id="flowPara2999">""")

    out.write(text.strip())

    out.write("</flowPara></flowRoot></g></svg>\n")


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")