Skip to content

Instantly share code, notes, and snippets.

@mansarip
Last active April 18, 2026 23:29
Show Gist options
  • Select an option

  • Save mansarip/eb11b66e7dc65cee988155275a17a119 to your computer and use it in GitHub Desktop.

Select an option

Save mansarip/eb11b66e7dc65cee988155275a17a119 to your computer and use it in GitHub Desktop.
How to use PDFKit with Hono + Bun

How to use PDFKit with Hono + Bun

Full example

import { Hono } from "hono";
import PDFDocument from "pdfkit";

const app = new Hono();

app.get("/pdf", async (c) => {
  const doc = new PDFDocument();
  doc.info.Title = "Test Document";
  doc.text("Salam!");
  doc.end();
  c.header("Content-Disposition", 'inline; filename="my-custom-filename.pdf"');
  return c.body(doc);
});

export default app;

You can also use new Response() instead of using context (c) from Hono :

app.get("/pdf", async (c) => {
  const doc = new PDFDocument();
  doc.info.Title = "Test Document";
  doc.text("Salam!");
  doc.end();
  return new Response(doc, {
    headers: {
      "Content-Disposition": 'inline; filename="apakah.pdf"',
    },
  });
});
@zulfio
Copy link
Copy Markdown

zulfio commented Oct 16, 2024

Thank you sarip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment