Guest User

feliam

a guest
Feb 11th, 2010
440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. import zlib,sys,md5
  7.  
  8. def _zipEmbeddeFile(doc, f,minimal=False):
  9.     fileStr = file(f).read()
  10.     embedded = PDFStream(fileStr)
  11.     if not minimal:
  12.         embedded.add('Type', PDFName('EmbeddedFile'))
  13. #        embedded.add('Subtype',PDFName('application#2Fpdf'))
  14.         embedded.add('Params',PDFDict({'Size': PDFNum(len(fileStr)),
  15.                                  'CheckSum': PDFOctalString(md5.new(fileStr).digest())}) )
  16.         embedded.add('DL', ' %d '%len(fileStr))
  17.     embedded.appendFilter(FlateDecode())
  18.     doc.add(embedded)
  19.  
  20.     #embedded list
  21.     embeddedlst = PDFDict()
  22.     embeddedlst.add('F',PDFRef(embedded))
  23.  
  24.     #fileSpec
  25.     filespec = PDFDict()
  26.     filespec.add('Type',PDFName('Filespec'))
  27.     filespec.add('F',PDFString(f))
  28.     filespec.add('EF', embeddedlst)
  29.     doc.add(filespec)
  30.     return filespec
  31.  
  32. #The document
  33. doc = PDFDoc()
  34.  
  35. #The withe page
  36. #contents
  37. contents = PDFStream('')
  38. doc.add(contents)
  39.  
  40. #page
  41. page = PDFDict()
  42. page.add("Type", PDFName("Page"))
  43. page.add("Contents", PDFRef(contents))
  44. doc.add(page)
  45.  
  46. #pages
  47. pages = PDFDict()
  48. pages.add("Type", PDFName("Pages"))
  49. pages.add("Kids", PDFArray([PDFRef(page)]))
  50. pages.add("Count", PDFNum(1))
  51. doc.add(pages)
  52.  
  53. #add parent reference in page
  54. page.add("Parent", PDFRef(pages))
  55.  
  56. #catalog
  57. catalog = PDFDict()
  58. catalog.add("Type", PDFName("Catalog"))
  59. catalog.add("Pages", PDFRef(pages))
  60. doc.add(catalog)
  61. doc.setRoot(catalog)
  62.  
  63.  
  64. #SWF PART BEGINS...
  65. #A name tree of embedded file specification dictionaries as detailed in
  66. #Section 3.10.2 of the PDF Reference, sixth edition.
  67. assets = PDFDict()
  68. swfname, efref = PDFString(sys.argv[1]),PDFRef(_zipEmbeddeFile(doc,sys.argv[1]))
  69. assets.add('Names',PDFArray([swfname, efref]))
  70. doc.add(assets)
  71.  
  72. #Astream with flash variables
  73. #flashVars = PDFStream(file(sys.argv[2]).read())
  74. #doc.add(flashVars)
  75.  
  76. #stream with flash variables
  77. auxiliar = PDFStream('''''')
  78. doc.add(auxiliar)
  79.  
  80. #TABLE 9.51c Entries in a RichMediaParams dictionary
  81. RMParams = PDFDict()
  82. RMParams.add('Type', PDFName('RichMediaParams'))
  83. RMParams.add('FlashVars', PDFString(file(sys.argv[2]).read()))
  84. RMParams.add('Binding', PDFName('Background'))
  85. RMParams.add('Settings', PDFRef(auxiliar))
  86. doc.add(RMParams)
  87.  
  88. #The instances list
  89. instances = []
  90. #TABLE 9.51b Entries in a RichMediaInstance dictionary
  91. RMI = PDFDict()
  92. RMI.add('Type',PDFName('RichMediaInstance'))
  93. RMI.add('Subype',PDFName('Flash'))
  94. RMI.add('Params',PDFRef(RMParams))
  95. RMI.add('Asset',efref)
  96. doc.add(RMI)
  97. instances.append(PDFRef(RMI))
  98.  
  99. #the configuration list
  100. configurations = []
  101. #TABLE 9.51a Entries in a RichMediaConfiguration dictionary
  102. RMCfg = PDFDict()
  103. RMCfg.add('Type',PDFName('RichMediaConfiguration'))
  104.  
  105. #Default value: If no value is specified, the run time determines the
  106. #scene type by referring to the type of asset file specified by the first
  107. #element in the Instances array.
  108. RMCfg.add('Subtype',PDFName('Flash'))
  109. RMCfg.add('Name',PDFString('ElFlash'))
  110. RMCfg.add('Instances', PDFArray(instances))
  111. doc.add(RMCfg)
  112. configurations.append(PDFRef(RMCfg))
  113.  
  114.  
  115.  
  116. #TABLE 9.50a Entries in a RichMediaDeactivation dictionary
  117. activation = PDFDict()
  118. activation.add('Type', PDFName('RichMediaActivation'))
  119. activation.add('Condition', PDFName('PO'))
  120. #Default value: The first element within the Configurations
  121. #array specified in the RichMediaContent dictionary.
  122. #activation.add('Configuration', PDFRef(...))
  123.  
  124. #An array of indirect object
  125. #references to file specification dictionaries, each of which
  126. #describe a JavaScript file that shall be present in the Assets
  127. #name tree of the RichMediaContent dictionary.
  128. #Default value: If the array has no elements, no script is
  129. #executed.
  130. #activation.add('Scripts',PDFArray([PDFRef(jsfile)]))
  131. doc.add(activation)
  132.  
  133. #TABLE 9.50b Entries in a RichMediaDeactivation dictionary
  134. deactivation = PDFDict()
  135. deactivation.add('Type', PDFName('RichMediaDeactivation'))
  136. deactivation.add('Condition', PDFName('XD'))
  137. doc.add(deactivation)
  138.  
  139. #RichMediaCfg
  140. #TABLE 9.50 Entries in a RichMediaSettings dictionary
  141. RMS = PDFDict()
  142. RMS.add('Type',PDFName('RichMediaSettings'))
  143. RMS.add('Subtype',PDFName('Flash'))
  144. RMS.add('Activation', PDFRef(activation))
  145. RMS.add('Deactivation', PDFRef(deactivation))
  146. doc.add(RMS)
  147.  
  148. #TABLE 9.51 Entries in a RichMediaContent dictionary
  149. RMC = PDFDict()
  150. RMC.add('Type', PDFName('RichMediaContent'))
  151. RMC.add('Assets', PDFRef(assets))
  152. RMC.add('Configurations',PDFArray(configurations))
  153. doc.add(RMC)
  154.  
  155.  
  156. #RichMedia annotation
  157. #Section 9.5 of the PDF Reference
  158. annot = PDFDict()
  159. annot.add('Type',PDFName('Annot'))
  160. annot.add('Subtype',PDFName('RichMedia'))
  161. annot.add('Rect','[ 266 116 430 204 ]')
  162. annot.add('NM',PDFString(sys.argv[1]))
  163. #9.6.1 RichMedia Annotations
  164. annot.add('RichMediaSettings', PDFRef(RMS))
  165. annot.add('RichMediaContent', PDFRef(RMC))
  166. doc.add(annot)
  167.  
  168. #add the RichMedia annotation to the 1st page
  169. page.add("Annots", PDFArray([PDFRef(annot)]))
  170. print doc
  171.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×