Skip to content

Commit bdfbd6a

Browse files
Merge pull request #1727 from hackforla/1688-pdf-page-cutoff
Account for multiple page PDF download #1688
2 parents e3474f5 + c5316cf commit bdfbd6a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

products/statement-generator/src/pages-form/Download.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)