source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-windows/examples/printheaderfooter.coffee@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

File size: 3.1 KB
Line 
1someCallback = (pageNum, numPages) ->
2 "<h1> someCallback: " + pageNum + " / " + numPages + "</h1>"
3page = require("webpage").create()
4system = require("system")
5if system.args.length < 3
6 console.log "Usage: printheaderfooter.js URL filename"
7 phantom.exit 1
8else
9 address = system.args[1]
10 output = system.args[2]
11 page.viewportSize =
12 width: 600
13 height: 600
14
15 page.paperSize =
16 format: "A4"
17 margin: "1cm"
18
19 # default header/footer for pages that don't have custom overwrites (see below)
20 header:
21 height: "1cm"
22 contents: phantom.callback((pageNum, numPages) ->
23 return "" if pageNum is 1
24 "<h1>Header <span style='float:right'>" + pageNum + " / " + numPages + "</span></h1>"
25 )
26
27 footer:
28 height: "1cm"
29 contents: phantom.callback((pageNum, numPages) ->
30 return "" if pageNum is numPages
31 "<h1>Footer <span style='float:right'>" + pageNum + " / " + numPages + "</span></h1>"
32 )
33
34 page.open address, (status) ->
35 if status isnt "success"
36 console.log "Unable to load the address!"
37 else
38
39 # check whether the loaded page overwrites the header/footer setting,
40 # i.e. whether a PhantomJSPriting object exists. Use that then instead
41 # of our defaults above.
42 #
43 # example:
44 # <html>
45 # <head>
46 # <script type="text/javascript">
47 # var PhantomJSPrinting = {
48 # header: {
49 # height: "1cm",
50 # contents: function(pageNum, numPages) { return pageNum + "/" + numPages; }
51 # },
52 # footer: {
53 # height: "1cm",
54 # contents: function(pageNum, numPages) { return pageNum + "/" + numPages; }
55 # }
56 # };
57 # </script>
58 # </head>
59 # <body><h1>asdfadsf</h1><p>asdfadsfycvx</p></body>
60 # </html>
61 #
62 if page.evaluate(->
63 typeof PhantomJSPrinting is "object"
64 )
65 paperSize = page.paperSize
66 paperSize.header.height = page.evaluate(->
67 PhantomJSPrinting.header.height
68 )
69 paperSize.header.contents = phantom.callback((pageNum, numPages) ->
70 page.evaluate ((pageNum, numPages) ->
71 PhantomJSPrinting.header.contents pageNum, numPages
72 ), pageNum, numPages
73 )
74 paperSize.footer.height = page.evaluate(->
75 PhantomJSPrinting.footer.height
76 )
77 paperSize.footer.contents = phantom.callback((pageNum, numPages) ->
78 page.evaluate ((pageNum, numPages) ->
79 PhantomJSPrinting.footer.contents pageNum, numPages
80 ), pageNum, numPages
81 )
82 page.paperSize = paperSize
83 console.log page.paperSize.header.height
84 console.log page.paperSize.footer.height
85 window.setTimeout (->
86 page.render output
87 phantom.exit()
88 ), 200
Note: See TracBrowser for help on using the repository browser.