Did I find the right examples for you? yes no

All Samples(3)  |  Call(1)  |  Derive(0)  |  Import(2)

        def pisaDocument(
    src,
    dest = None,
    path = None,
    link_callback = None,
    debug = 0,
    show_error_as_pdf = False,
    default_css = None,
    xhtml = False,
    encoding = None,
    xml_output = None,
    raise_exception = True,
    capacity = 100 * 1024, # -1,
    **kw):
    
    c = None    
    if show_error_as_pdf:
        raise_exception = False
    
    try:

        log.debug("pisaDocument options:\n  src = %r\n  dest = %r\n  path = %r\n  link_callback = %r\n  xhtml = %r",
            src,
            dest,
            path,
            link_callback,
            xhtml)

        # Prepare simple context
        c = pisaContext(path, debug=debug, capacity=capacity)
        c.pathCallback = link_callback

        if dest is None:
            dest = pisaTempFile(capacity=c.capacity)
        c.dest = dest

        # Build story
        c = pisaStory(src, path, link_callback, debug, default_css, xhtml, encoding, c=c, xml_output=xml_output)

        # Buffer PDF into memory
        out = pisaTempFile(capacity=c.capacity)

        doc = PmlBaseDoc(
            out,
            pagesize = c.pageSize,
            author = c.meta["author"].strip(),
            subject = c.meta["subject"].strip(),
            keywords = [x.strip() for x in c.meta["keywords"].strip().split(",") if x],
            title = c.meta["title"].strip(),
            showBoundary = 0,
            allowSplitting = 1)

        # XXX It is not possible to access PDF info, because it is private in canvas
        # doc.info.producer = "pisa "

        # Prepare templates and their frames
        if c.templateList.has_key("body"):
            body = c.templateList["body"]
            del c.templateList["body"]
        else:
            x, y, w, h = getBox("1cm 1cm -1cm -1cm", c.pageSize)
            body = PmlPageTemplate(
                id="body",
                frames=[
                    Frame(x, y, w, h,
                        id = "body",
                        leftPadding = 0,
                        rightPadding = 0,
                        bottomPadding = 0,
                        topPadding = 0)],
                pagesize = c.pageSize)

        # print body.frames

        # print [body] + c.templateList.values()
        doc.addPageTemplates([body] + c.templateList.values())

        # Use multibuild e.g. if a TOC has to be created
        if c.multiBuild:
            doc.multiBuild(c.story)
        else:
            doc.build(c.story)

        # Add watermarks
        if pyPdf:                      
            for bgouter in c.pisaBackgroundList:     
                          
                # If we have at least one background, then lets do it
                if bgouter:
                    
                    istream = out                    
                    try:
                        output = pyPdf.PdfFileWriter()
                        input1 = pyPdf.PdfFileReader(istream)
                        ctr = 0
                        for bg in c.pisaBackgroundList:                            
                            page = input1.getPage(ctr)
                            if bg and not bg.notFound() and (bg.mimetype=="application/pdf"):
                                bginput = pyPdf.PdfFileReader(bg.getFile())
                                pagebg = bginput.getPage(0)
                                pagebg.mergePage(page)
                                page = pagebg
                            else:
                                log.warn(c.warning("Background PDF %s doesn't exist.", bg))
                            output.addPage(page)
                            ctr += 1
                        out = pisaTempFile(capacity=c.capacity)
                        output.write(out)
                        # data = sout.getvalue()
                    except Exception:
                        log.exception(c.error("pyPDF error"))   
                        if raise_exception:
                            raise
                 
                    
                    # Found a background? So leave loop after first occurence
                    break
        else:
            log.warn(c.warning("pyPDF not installed!"))

        # In web frameworks for debugging purposes maybe an output of
        # errors in a PDF is preferred        
        if show_error_as_pdf and c and c.err:
            return pisaErrorDocument(c.dest, c)

        # Get the resulting PDF and write it to the file object
        # passed from the caller
        data = out.getvalue()
        c.dest.write(data)
            
    except:
        # log.exception(c.error("Document error"))        
        log.exception("Document error")
        c.err += 1
        if raise_exception:
            raise

    if raise_exception and c.err:
        raise Exception("Errors occured, please see log files for more informations") 

    return c
        


src/z/o/zopyx.convert2-2.4.5/src/zopyx/convert2/pisa.py   zopyx.convert2(Download)
 
from exceptions import ConversionError
from sx.pisa3.pisa_document import pisaDocument
 
 
    fin = file(html_filename)
    fout = file(output_filename, 'wb')
    pisaDocument(fin, 
                 fout,
                 encoding='utf-8',

src/z/o/zopyx.convert2-2.4.5/src/zopyx/convert2/pisa_bin.py   zopyx.convert2(Download)
 
from exceptions import ConversionError
from sx.pisa3.pisa_document import pisaDocument