Skip to content

Commit

Permalink
fix(pdf): blank page
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Nov 12, 2024
1 parent 762821e commit 6332499
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/frontend/src/routes/pdf.$reportId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ const View = (props: ReportPDFDocumentProps) => {
return blob;
},
refetchOnWindowFocus: false,
enabled: !!props.htmlString,
});

if (query.isLoading) return <Spinner />;
Expand Down
49 changes: 37 additions & 12 deletions packages/pdf/src/report.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Document, Font, Image, Page, View } from "@react-pdf/renderer";
import { Document, Font, Image, Page, Text, View } from "@react-pdf/renderer";
import { Html } from "react-pdf-html";
import React from "react";
import type { Udap, Report, Service_instructeurs, Clause_v2, Pictures } from "@cr-vif/electric-client/frontend";
Expand All @@ -10,16 +10,17 @@ Font.registerHyphenationCallback((word) => {

export const ReportPDFDocument = ({ udap, htmlString, images, pictures }: ReportPDFDocumentProps) => {
return (
<Document>
<Document onRender={console.log}>
<Page
minPresenceAhead={20}
size="A4"
style={{
paddingTop: "48px",
paddingBottom: "32px",
}}
>
<Html
resetStyles
collapse
style={{
fontSize: "10px",
paddingLeft: "32px",
Expand Down Expand Up @@ -154,16 +155,40 @@ export const ReportPDFDocument = ({ udap, htmlString, images, pictures }: Report
</body>
</html>
`}</Html>
{pictures ? (
<View break>
{pictures
.filter((pic) => !!pic.url)
.map((pic) => (
<Image key={pic.id} style={{ width: `100%`, height: "auto" }} src={pic.url!} />
))}
</View>
) : null}
</Page>
{pictures
? pictures
.filter((pic) => !!pic.url)
.map((pic, index) => (
<Page
break={index > 0}
style={{
paddingTop: "48px",
paddingBottom: "32px",
maxHeight: "100vh",
}}
key={pic.id}
size="A4"
>
<View
style={{
marginHorizontal: "10%",
maxHeight: "100vh",
}}
>
<Image
style={{
width: `auto`,
height: "auto",
objectFit: "contain",
overflow: "hidden",
}}
src={pic.url!}
/>
</View>
</Page>
))
: null}
</Document>
);
};
Expand Down

0 comments on commit 6332499

Please sign in to comment.