How Prince PDF Export Works

    Table of contents
    No headers

    The following describes how the GET:pages/{pageid}/pdf feature works.

     

    • User-Agent does a GET on /deki/pages/{pageid}/pdf
    • READ permissions are checked
    • DekiXmlParser is in invoked to get the XHTML
    • XDoc is created with html, head, title, body tags
    • XDoc head and body section is populated with parser.Head, parser.MainBody
    • Locate all the img tags using XPATH, append an authtoken to all relative links (so images on restricted pages can be downloaded)
    • Add the XHTML Doctype to the begining of the XDoc to make prince happy
    • Convert the XDoc to a MemoryStream so we can pipe it into stdin when invoking prince
    • Invoke prince to generate the PDF and capture stdout
    • Set the ContentDisposition header using filename={page_title}.pdf
    • write the stdout stream to the browser  

     

    The prince binary is invoked as follows:

    /usr/bin/prince --input=xml -s http://yoursite.com/skins/common/prince.css --baseurl=http://yoursite.com - -o -
    

    The arguments are this:

    --input=xml:  use prince's xml/xhtml parser

    -s:  the css stylesheet to use

    --baseurl: base url to use for relative links

    -: read input from stdin

    -o -: write output to stdout

    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by