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"',
},
});
});
Thank you sarip