Skip to content

Helvetica.afm file missing in Next.js #1549

Description

@james-beston

Bug Report

No Helvetica.afm file is being created when I use Next.js locally.

Description of the problem

I have to manually create a) the data folder and b) the Helvetica.afm file in .next/server/vendor-chunks every time I start the project.

Code sample

import { NextResponse } from 'next/server';
import PDFDocument from 'pdfkit';

export async function GET() {
  // Create a new PDF document
  const doc = new PDFDocument();

  // Create a buffer to store the PDF data
  const pdfBuffer: Buffer = await new Promise((resolve, reject) => {
    const buffers: Uint8Array[] = [];
    doc.on('data', buffers.push.bind(buffers));
    doc.on('end', () => {
      const pdfData = Buffer.concat(buffers);
      resolve(pdfData);
    });

    // Add content to the PDF document
    doc.fontSize(25).text('Hello, world!', 100, 100);
    doc.fontSize(12).text('This PDF was generated server-side with pdfkit in Next.js.', 100, 150);

    // Finalize the PDF
    doc.end();
  });

  // Return the PDF as a response
  return new NextResponse(pdfBuffer, {
    headers: {
      'Content-Type': 'application/pdf',
      'Content-Length': pdfBuffer.length.toString(),
      'Content-Disposition': 'inline; filename="output.pdf"', // or 'attachment;' for download
    },
  });
}

Your environment

  • pdfkit version: 0.15.0
  • Node version: 20.12.2
  • Next version: 14.2.9
  • React version: 18.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions