Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,53 @@ export default function Home() {
}
};

const handleDownloadPdf = async () => {
if (!coverLetter) {
return;
}

try {
const { jsPDF } = await import('jspdf');

const doc = new jsPDF({
unit: 'pt',
format: 'letter',
orientation: 'portrait'
});

const leftMargin = 72; // 1 inch
const rightMargin = 72;
const topMargin = 72;
const bottomMargin = 72;
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
const contentWidth = pageWidth - leftMargin - rightMargin;

const fontSize = 12;
const lineHeight = fontSize * 1.2;

doc.setFont('Times', 'Normal');
doc.setFontSize(fontSize);

const lines = doc.splitTextToSize(coverLetter, contentWidth);

let cursorY = topMargin;

lines.forEach((line) => {
if (cursorY + lineHeight > pageHeight - bottomMargin) {
doc.addPage();
cursorY = topMargin;
}
doc.text(line, leftMargin, cursorY);
cursorY += lineHeight;
});

doc.save('cover-letter.pdf');
} catch (err) {
setError('Failed to generate PDF: ' + (err?.message || 'Unknown error'));
}
};

return (
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 py-12 px-4 sm:px-6 lg:px-8">
<div className="max-w-3xl mx-auto">
Expand Down Expand Up @@ -366,6 +413,14 @@ export default function Home() {
>
Copy to Clipboard
</button>
<button
type="button"
onClick={handleDownloadPdf}
disabled={!coverLetter}
className="flex-1 bg-purple-600 text-white py-3 px-6 rounded-lg font-semibold hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 transition disabled:opacity-50 disabled:cursor-not-allowed"
>
Download PDF
</button>
</div>

<div className="pt-4 border-t border-gray-200">
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"next": "16.0.10",
"openai": "^4.73.0",
"pdf-parse": "^1.1.1",
"jspdf": "^2.5.1",
"react": "19.2.0",
"react-dom": "19.2.0"
},
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.