PDF Generation Issue: Footer Images Not Rendering & "Buffer is not defined" Warning

Open
#3,225 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
react, typescript
Domain
frontend, web-dev

Research direction

Start with pdfHeader.jsx and pdfFooter.jsx, then reproduce the deployed Netlify case using @react-pdf/renderer v4.3.0 while checking the reported console warnings. Compare the two image URLs and verify that the footer image renders in the deployed PDF without the reported warnings.

Written by the indexing model from the issue text.

Description

When generating a prescription PDF using @react-pdf/renderer, the footer image fails to render on the deployed Netlify environment, although the header image and a separate signature image (both loaded via URL) render correctly. Additionally, the console displays "Buffer is not defined" and "Not valid image extension" warnings.

The issue initially arose when deploying, as image assets loaded from the frontend's public folder failed to load, reporting "Buffer is not defined". Moving the image assets to the backend and providing direct URLs resolved the header and signature issues, but the footer image issue persists only on the deployed version.


Screenshots

LocalHost When Making pdf with images in the public folder(Header & Footer Visible)
Image

Image

Netlify when making pdf with images in the public folder(Both Header and Footer not Visible)

Image

Local/Netlify when making pdf with images coming from backend(Header Visible but not Footer)

Image Image

But the Image Path is correct when accessed in browser directly

Image

Code for when Header is working fine but footer is not

// pdfHeader.jsx

import React from "react";
import { View, Text, Image } from "@react-pdf/renderer";
import { styles } from "../styles";
import { environmentUrls } from "../../../constants";

const PDFHeader = () => {
  const HeaderImg = `${environmentUrls.file_url}/uploads/document-header.png`;
  console.log("HeaderImg", HeaderImg);

  return (
    <View style={styles.header} fixed>
      <View
        style={{
          flexDirection: "row",
          justifyContent: "space-between",
          alignItems: "center",
          padding: 10,
        }}
      >
        {/* Logo or left content */}
        <Image src={HeaderImg} style={styles.header} />
      </View>
    </View>
  );
};
export default PDFHeader;

//pdfFooter.jsx

import { Image, View } from "@react-pdf/renderer";
import { styles } from "../styles";
import { environmentUrls } from "../../../constants";

const PDFFooter = () => {
  const FooterImg = `${environmentUrls.file_url}/uploads/document-footer.png`;
  console.log("FooterImg", FooterImg);

  return (
    <View style={styles.footer} fixed>
      <Image src={FooterImg} style={styles.footer} />
    </View>
  );
};

export default PDFFooter;

Also Styling is not an issue since FooterImg when replaced with header's link , renders successfully at the footer's place

PDF Library: @react-pdf/renderer v4.3.0
Browser: Google Chrome
Operating System (Dev): Linux Ubuntu
Deployment: Netlify

Dominant language
TypeScript
Stars
16.9k
Forks
1.3k
Avg merge
11m
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diegomura/react-pdf

All issues in diegomura/react-pdf

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.