@@ -104,11 +104,22 @@ <h1>Pixel Math Worksheet Generator</h1>
104104 < button id ="btnPixelate " class ="grow "> Pixelate</ button >
105105 < button id ="btnGenerate " class ="grow "> Generate</ button >
106106 </ div >
107+
108+ < div class ="row " style ="margin-top:4px; ">
109+ < label style ="display:flex;align-items:center;gap:6px; ">
110+ < input id ="includeAnswerKey " type ="checkbox " checked />
111+ Include Answer Key in PDF
112+ </ label >
113+ </ div >
114+
107115 < div class ="row ">
108116 < button id ="btnSave " class ="grow secondary "> Save PDF</ button >
109117 </ div >
110118 < div class ="note "> “Save PDF” opens the print dialog; choose “Save as PDF”.</ div >
111119 </ div >
120+
121+
122+
112123
113124 < div class ="card ">
114125 < div class ="label "> Original (fit)</ div >
@@ -147,6 +158,7 @@ <h1>Pixel Math Worksheet Generator</h1>
147158 const colsEl = document . getElementById ( 'cols' ) ;
148159 const rowsEl = document . getElementById ( 'rows' ) ;
149160 const kEl = document . getElementById ( 'kcolors' ) ;
161+ const includeAnswerKeyEl = document . getElementById ( 'includeAnswerKey' ) ;
150162
151163 const origCanvas = document . getElementById ( 'origCanvas' ) ;
152164 const pixCanvas = document . getElementById ( 'pixCanvas' ) ;
@@ -646,17 +658,24 @@ <h1>Pixel Math Worksheet Generator</h1>
646658 worksheetPreviewImg . src = wsURL ;
647659 worksheetPrintImg . src = wsURL ;
648660
649- // Page 2: answer key (full page color)
650- const ansCanvas = renderAnswerCanvas ( ) ;
651- const ansURL = ansCanvas . toDataURL ( 'image/png' ) ;
652- answerPreviewImg . src = ansURL ;
653- answerPrintImg . src = ansURL ;
661+ // Conditionally include answer key
662+ if ( includeAnswerKeyEl . checked ) {
663+ const ansCanvas = renderAnswerCanvas ( ) ;
664+ const ansURL = ansCanvas . toDataURL ( 'image/png' ) ;
665+ answerPreviewImg . src = ansURL ;
666+ answerPrintImg . src = ansURL ;
667+ answerPrintImg . style . display = "block" ;
668+ } else {
669+ answerPreviewImg . removeAttribute ( 'src' ) ;
670+ answerPrintImg . removeAttribute ( 'src' ) ;
671+ answerPrintImg . style . display = "none" ;
672+ }
654673
655674 worksheetPreviewImg . scrollIntoView ( { behavior :'smooth' , block :'center' } ) ;
656675 } ) ;
657676
658677 document . getElementById ( 'btnSave' ) . addEventListener ( 'click' , ( ) => {
659- if ( ! worksheetPrintImg . src || ! answerPrintImg . src ) {
678+ if ( ! worksheetPrintImg . src ) {
660679 const proceed = confirm ( 'You have not generated worksheet/answer images yet.\nOpen the print dialog anyway?' ) ;
661680 if ( ! proceed ) return ;
662681 }
0 commit comments