Advertisement
Guest User

feliam

a guest
Feb 11th, 2010
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. ##########################################################################
  2. ####   Felipe Andres Manzano     *   felipe.andres.manzano@gmail.com  ####
  3. ####   http://twitter.com/feliam *   http://wordpress.com/feliam      ####
  4. ##########################################################################
  5. from miniPDF import *
  6.  
  7. #First we import the lib and create a PDFDoc object representing a document in memory ...
  8. doc = PDFDoc()
  9.  
  10. #... prepare an empty content stream for the page and add it to the document.
  11. contents = PDFStream('')
  12. doc.add(contents)
  13.  
  14. #The minimal page object. We construct it and add it to the document like this ...
  15. page = PDFDict()
  16. page.add("Type", PDFName("Page"))
  17. page.add("Contents", PDFRef(contents))
  18. doc.add(page)
  19.  
  20. #... then we need the list of pages. In this case containing just or blank page.
  21. pages = PDFDict()
  22. pages.add("Type", PDFName("Pages"))
  23. pages.add("Kids", PDFArray([PDFRef(page)]))
  24. pages.add("Count", PDFNum(1))
  25. doc.add(pages)
  26.  
  27. #Lets be nice and honor the PDF structure as stated in .We link the page to its parent.
  28. page.add("Parent", PDFRef(pages))
  29.  
  30. #And finally we add the catalog wich is the root object of this PDF.
  31. catalog = PDFDict()
  32. catalog.add("Type", PDFName("Catalog"))
  33. catalog.add("Pages", PDFRef(pages))
  34. doc.add(catalog)
  35. doc.setRoot(catalog)
  36.  
  37. #If we render that like this...
  38. print doc
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement