Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##########################################################################
- #### Felipe Andres Manzano * felipe.andres.manzano@gmail.com ####
- #### http://twitter.com/feliam * http://wordpress.com/feliam ####
- ##########################################################################
- from miniPDF import *
- #First we import the lib and create a PDFDoc object representing a document in memory ...
- doc = PDFDoc()
- #... prepare an empty content stream for the page and add it to the document.
- contents = PDFStream('')
- doc.add(contents)
- #The minimal page object. We construct it and add it to the document like this ...
- page = PDFDict()
- page.add("Type", PDFName("Page"))
- page.add("Contents", PDFRef(contents))
- doc.add(page)
- #... then we need the list of pages. In this case containing just or blank page.
- pages = PDFDict()
- pages.add("Type", PDFName("Pages"))
- pages.add("Kids", PDFArray([PDFRef(page)]))
- pages.add("Count", PDFNum(1))
- doc.add(pages)
- #Lets be nice and honor the PDF structure as stated in .We link the page to its parent.
- page.add("Parent", PDFRef(pages))
- #And finally we add the catalog wich is the root object of this PDF.
- catalog = PDFDict()
- catalog.add("Type", PDFName("Catalog"))
- catalog.add("Pages", PDFRef(pages))
- doc.add(catalog)
- doc.setRoot(catalog)
- #If we render that like this...
- print doc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement