Skip to content

Error during PDF conversion: ReferenceError: File is not defined #1

@moe12572

Description

@moe12572

I keep getting an error when running npm run render:

import "dotenv/config";

import fs from "fs";
import { FileforgeClient } from '@fileforge/client';
import { compile } from "@fileforge/react-print";
import React from "react";

import { Document } from "./Document";

const ff = new FileforgeClient({
  apiKey:"process.env.FILEFORGE_API_KEY", // replace with your API key
});

(async () => {
  try {
    const HTML = await compile(<Document name="World" />)

    const pdf = await ff.pdf.generate(
      [new File([HTML], "index.html", {
        type: "text/html",
      }),
       new File([fs.readFileSync(__dirname + "/images/fileforge_cover.png")], "fileforge_cover.png", {
        type: "image/png",  
       })
    ],
      {
        options: {
          host: false,
          test: false,
        },
      }
    );

    pdf.pipe(fs.createWriteStream("output.pdf"));
  } catch (error) {
    console.error("Error during PDF conversion:", error);
  }
})();

Screenshot 2024-07-03 at 11 54 51 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions