|
| 1 | +component extends="org.lucee.cfml.test.LuceeTestCase" labels="pdf" { |
| 2 | + |
| 3 | + function beforeAll() { |
| 4 | + variables.path = getDirectoryFromPath( getCurrentTemplatePath() ) & "DocumentHeaderFooter/"; |
| 5 | + afterAll(); |
| 6 | + |
| 7 | + if ( !directoryExists( variables.path ) ) directoryCreate( variables.path ); |
| 8 | + } |
| 9 | + |
| 10 | + function run( testResults, testBox ) { |
| 11 | + describe( "cfdocument headers", function() { |
| 12 | + |
| 13 | + it( title="document with header", body=function( currentSpec ) { |
| 14 | + document format="pdf" filename="#path#with_header.pdf" overwrite=true { |
| 15 | + documentItem type="header" { |
| 16 | + writeOutput( "<div style='text-align:center;'>Document Header</div>" ); |
| 17 | + } |
| 18 | + writeOutput( "<h1>Content</h1><p>This document has a header.</p>" ); |
| 19 | + } |
| 20 | + |
| 21 | + expect( isPDFFile( "#path#with_header.pdf" ) ).toBeTrue(); |
| 22 | + }); |
| 23 | + |
| 24 | + it( title="header appears on all pages", body=function( currentSpec ) { |
| 25 | + document format="pdf" filename="#path#header_multipage.pdf" overwrite=true { |
| 26 | + documentItem type="header" { |
| 27 | + writeOutput( "<div>Page Header</div>" ); |
| 28 | + } |
| 29 | + writeOutput( "<h1>Page 1</h1>" ); |
| 30 | + documentItem type="pagebreak"; |
| 31 | + writeOutput( "<h1>Page 2</h1>" ); |
| 32 | + documentItem type="pagebreak"; |
| 33 | + writeOutput( "<h1>Page 3</h1>" ); |
| 34 | + } |
| 35 | + |
| 36 | + expect( isPDFFile( "#path#header_multipage.pdf" ) ).toBeTrue(); |
| 37 | + pdf action="getInfo" source="#path#header_multipage.pdf" name="local.info"; |
| 38 | + expect( info.totalPages ).toBe( 3 ); |
| 39 | + }); |
| 40 | + |
| 41 | + }); |
| 42 | + |
| 43 | + describe( "cfdocument footers", function() { |
| 44 | + |
| 45 | + it( title="document with footer", body=function( currentSpec ) { |
| 46 | + document format="pdf" filename="#path#with_footer.pdf" overwrite=true { |
| 47 | + documentItem type="footer" { |
| 48 | + writeOutput( "<div style='text-align:center;'>Document Footer</div>" ); |
| 49 | + } |
| 50 | + writeOutput( "<h1>Content</h1><p>This document has a footer.</p>" ); |
| 51 | + } |
| 52 | + |
| 53 | + expect( isPDFFile( "#path#with_footer.pdf" ) ).toBeTrue(); |
| 54 | + }); |
| 55 | + |
| 56 | + it( title="footer appears on all pages", body=function( currentSpec ) { |
| 57 | + document format="pdf" filename="#path#footer_multipage.pdf" overwrite=true { |
| 58 | + documentItem type="footer" { |
| 59 | + writeOutput( "<div>Page Footer</div>" ); |
| 60 | + } |
| 61 | + writeOutput( "<h1>Page 1</h1>" ); |
| 62 | + documentItem type="pagebreak"; |
| 63 | + writeOutput( "<h1>Page 2</h1>" ); |
| 64 | + } |
| 65 | + |
| 66 | + expect( isPDFFile( "#path#footer_multipage.pdf" ) ).toBeTrue(); |
| 67 | + pdf action="getInfo" source="#path#footer_multipage.pdf" name="local.info"; |
| 68 | + expect( info.totalPages ).toBe( 2 ); |
| 69 | + }); |
| 70 | + |
| 71 | + }); |
| 72 | + |
| 73 | + describe( "cfdocument header and footer combined", function() { |
| 74 | + |
| 75 | + it( title="document with both header and footer", body=function( currentSpec ) { |
| 76 | + document format="pdf" filename="#path#header_footer.pdf" overwrite=true { |
| 77 | + documentItem type="header" { |
| 78 | + writeOutput( "<div style='border-bottom:1px solid black;'>Header Content</div>" ); |
| 79 | + } |
| 80 | + documentItem type="footer" { |
| 81 | + writeOutput( "<div style='border-top:1px solid black;'>Footer Content</div>" ); |
| 82 | + } |
| 83 | + writeOutput( "<h1>Main Content</h1><p>This document has both header and footer.</p>" ); |
| 84 | + } |
| 85 | + |
| 86 | + expect( isPDFFile( "#path#header_footer.pdf" ) ).toBeTrue(); |
| 87 | + }); |
| 88 | + |
| 89 | + it( title="header and footer with page numbers", body=function( currentSpec ) { |
| 90 | + document format="pdf" filename="#path#page_numbers.pdf" overwrite=true { |
| 91 | + documentItem type="header" { |
| 92 | + writeOutput( "<div>Report Title</div>" ); |
| 93 | + } |
| 94 | + documentItem type="footer" evalAtPrint=true { |
| 95 | + writeOutput( "<div style='text-align:center;'>Page ##cfdocument.currentpagenumber## of ##cfdocument.totalpagecount##</div>" ); |
| 96 | + } |
| 97 | + writeOutput( "<h1>Page 1 Content</h1>" ); |
| 98 | + documentItem type="pagebreak"; |
| 99 | + writeOutput( "<h1>Page 2 Content</h1>" ); |
| 100 | + documentItem type="pagebreak"; |
| 101 | + writeOutput( "<h1>Page 3 Content</h1>" ); |
| 102 | + } |
| 103 | + |
| 104 | + expect( isPDFFile( "#path#page_numbers.pdf" ) ).toBeTrue(); |
| 105 | + pdf action="getInfo" source="#path#page_numbers.pdf" name="local.info"; |
| 106 | + expect( info.totalPages ).toBe( 3 ); |
| 107 | + }); |
| 108 | + |
| 109 | + }); |
| 110 | + } |
| 111 | + |
| 112 | + function afterAll() { |
| 113 | + if ( directoryExists( variables.path ) ) directoryDelete( variables.path, true ); |
| 114 | + } |
| 115 | +} |
0 commit comments