Skip to content

Commit e5c4e87

Browse files
authored
Merge pull request #124 from Dawn-Fighter/fix/resume-download-tobuffer
fix: use renderToBuffer to fix resume download (#89)
2 parents 79bc9f9 + 3baacda commit e5c4e87

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

www/app/api/resume/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ export async function GET(request: NextRequest) {
1010
return Response.json({ error: "Username is required" }, { status: 400 });
1111
}
1212

13-
const pdfInstance = await generateResumePDF(username);
14-
const pdfBuffer = await pdfInstance.toBuffer();
13+
const pdfBuffer = await generateResumePDF(username);
1514

16-
//@ts-expect-error -- todo: fix this later
1715
return new Response(pdfBuffer, {
1816
headers: {
1917
"Content-Type": "application/pdf",

www/components/ClientResumeButton.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ export default function ClientResumeButton({ username }: { username: string }) {
2222

2323
const blob = await response.blob();
2424
const url = URL.createObjectURL(blob);
25-
window.open(url, "_blank");
25+
const a = document.createElement("a");
26+
a.href = url;
27+
a.download = `${username}-resume.pdf`;
28+
document.body.appendChild(a);
29+
a.click();
30+
document.body.removeChild(a);
31+
URL.revokeObjectURL(url);
2632
} catch (error) {
2733
console.error("Error downloading resume:", error);
34+
alert("Failed to generate resume. Please try again.");
2835
} finally {
2936
setIsLoading(false);
3037
}

www/lib/resume.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Image,
44
Link,
55
Page,
6-
pdf,
6+
renderToBuffer,
77
StyleSheet,
88
Text,
99
View,
@@ -379,7 +379,7 @@ async function getResumeData(username: string): Promise<ResumeData> {
379379
};
380380
}
381381

382-
export async function generateResumePDF(username: string) {
382+
export async function generateResumePDF(username: string): Promise<Buffer> {
383383
const resumeData = await getResumeData(username);
384-
return pdf(<ResumeDocument data={resumeData} />);
384+
return renderToBuffer(<ResumeDocument data={resumeData} />);
385385
}

0 commit comments

Comments
 (0)