File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
products/statement-generator/src/pages-form Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -136,8 +136,28 @@ export default function Download({ onDownloadAgreementCheck }: IDownload) {
136136 const handleClickPDF = ( ) => {
137137 const doc = new jsPDF ( 'p' , 'mm' , 'letter' ) ;
138138 doc . setFontSize ( 12 ) ;
139- const lines = doc . splitTextToSize ( finalStatement , 170 ) ;
140- doc . text ( 20 , 50 , lines ) ;
139+
140+ const marginLeft = 20 ;
141+ const marginTop = 30 ;
142+ const marginBottom = 30 ;
143+ const maxWidth = 170 ;
144+ const lineHeight = 6 ;
145+ const pageHeight = doc . internal . pageSize . height ;
146+
147+ let y = marginTop ;
148+
149+ const lines = doc . splitTextToSize ( finalStatement , maxWidth ) ;
150+
151+ // account for spillover onto multiple pages
152+ lines . forEach ( ( line : string ) => {
153+ if ( y + lineHeight > pageHeight - marginBottom ) {
154+ doc . addPage ( ) ;
155+ y = 30 ;
156+ }
157+ doc . text ( marginLeft , y , line ) ;
158+ y += lineHeight ;
159+ } ) ;
160+
141161 doc . save ( 'MyPersonalStatement.pdf' ) ;
142162 } ;
143163
You can’t perform that action at this time.
0 commit comments