def main(argv): document = dsc_document("EPS Demo") page = document.page() canvas = page.canvas(margin=mm(18), border=True) eps = eps_image(canvas, open(sys.argv[1]), border=True, document_level=True) page.append(eps) fp = open(sys.argv[1] + ".ps", "w") document.write_to(fp) fp.close()
def my_document(ds): document = dsc_document() dir = dirname(__file__) if dir == "": dir = "." print >> debug, "Loading background" background = eps_image(document, open(dir + "/conditions_background.eps")) print >> debug, "Loading fonts" italic = type1(open(pjoin(dir, "italic.pfb")), open(pjoin(dir, "italic.afm"))) bold = type1(open(pjoin(dir, "bold.pfb")), open(pjoin(dir, "bold.afm"))) bolditalic = type1(open(pjoin(dir, "bolditalic.pfb")), open(pjoin(dir, "bolditalic.afm"))) # Define the relevant styles. h1 = style(font=bolditalic, font_size=9.2, color="0.98 0 0.48 0.63 setcmykcolor", margin_top=mm(2)) h2 = style(font=bolditalic, font_size=8, color="0 setgray", margin_top=mm(2)) description = style(font=italic, font_size=7, color="0 setgray", padding_top=2, padding_bottom=1, text_align="justify") tabelle_dunkel = style(font=italic, font_size=7, color="0 setgray", background_color="1 0.24 sub setgray", padding_top=2, padding_bottom=1, padding_right=2) tabelle_hell = style(font=italic, font_size=7, color="0 setgray", background_color="1 0.12 sub setgray", padding_top=2, padding_bottom=1, padding_right=2) # Create the divs print >> debug, "Making db requests" divs = [] pages = ds.select(schema.page) tabcounter = 0 for page in pages: ds = [] ds.append(div(page.name, h1)) entries = page.entries.select() for entry in entries: if entry.type == "caption": if entry.value1 is not None and strip(entry.value1) != "": ds.append(div(entry.value1, h2)) if entry.value2 is not None and strip(entry.value2) != "": ds.append(div(entry.value2, description)) elif entry.type == "info": if entry.value2 is None or strip(entry.value2) == "": ds.append(div(entry.value1, description)) else: cls = ( tabelle_dunkel, tabelle_hell, )[tabcounter%2] tabcounter += 1 ds.append(lr_div(entry.value1, entry.value2, cls)) divs.append(div_div(ds)) # layout print >> debug, "Starting layout process" layout(divs, new_page(document, background, italic)) return document