Skip to content

Commit

Permalink
make react-pdf work
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Dec 24, 2024
1 parent 69703a9 commit 1820be1
Show file tree
Hide file tree
Showing 8 changed files with 11,521 additions and 13,654 deletions.
13 changes: 0 additions & 13 deletions apps/web/app/api/pdf/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
"use client";
import {
Document,
Page,
Text,
View,
renderToBuffer,
} from "@react-pdf/renderer";

import { Document, Page, Text, View } from "@react-pdf/renderer";
export const dynamic = "force-dynamic";

export function InvoiceTemplate({
invoice,
}: {
invoice: {
id: string;
date: string;
amount: number;
items: { description: string; quantity: number; price: number }[];
export async function GET() {
const invoice = {
id: "123",
date: "2021-01-01",
amount: 100,
items: [{ description: "Item 1", quantity: 1, price: 50 }],
};
}) {
return (

const pdf = await renderToBuffer(
<Document>
<Page size="A4">
<View>
Expand All @@ -32,6 +36,13 @@ export function InvoiceTemplate({
<Text>Total: {invoice.amount}</Text>
</View>
</Page>
</Document>
</Document>,
);

return new Response(pdf, {
headers: {
"Content-Type": "application/pdf",
"Content-disposition": "inline",
},
});
}
2 changes: 1 addition & 1 deletion apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const REDIRECT_SEGMENTS = [
/** @type {import('next').NextConfig} */
module.exports = withAxiom({
reactStrictMode: false,
transpilePackages: ["shiki", "@dub/prisma", "@dub/pdf"],
transpilePackages: ["shiki", "@dub/prisma"],
experimental: {
serverComponentsExternalPackages: [
"@react-email/components",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@dub/tailwind-config": "workspace:*",
"@dub/ui": "workspace:*",
"@dub/utils": "workspace:*",
"@dub/pdf": "workspace:*",
"@hookform/resolvers": "^3.9.0",
"@next-auth/prisma-adapter": "^1.0.5",
"@next/third-parties": "^15.1.0",
Expand All @@ -34,6 +33,7 @@
"@prisma/nextjs-monorepo-workaround-plugin": "^6.0.1",
"@radix-ui/react-hover-card": "^1.1.1",
"@react-email/components": "^0.0.22",
"@react-pdf/renderer": "4.1.5",
"@sindresorhus/slugify": "^2.2.1",
"@splinetool/react-spline": "^2.2.6",
"@splinetool/runtime": "^1.2.8",
Expand Down
30 changes: 0 additions & 30 deletions packages/pdf/package.json

This file was deleted.

28 changes: 0 additions & 28 deletions packages/pdf/src/index.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions packages/pdf/tsconfig.json

This file was deleted.

Loading

0 comments on commit 1820be1

Please sign in to comment.