https://github.com/kavindu-mane/html-to-pdf
Simple API for convert HTML to PDF. This API use puppeteer npm package as convertor.
https://github.com/kavindu-mane/html-to-pdf
bun hono html-to-pdf puppeteer
Last synced: about 2 months ago
JSON representation
Simple API for convert HTML to PDF. This API use puppeteer npm package as convertor.
- Host: GitHub
- URL: https://github.com/kavindu-mane/html-to-pdf
- Owner: kavindu-mane
- License: mit
- Created: 2024-04-10T15:28:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-19T09:17:59.000Z (11 months ago)
- Last Synced: 2025-10-29T02:47:58.853Z (8 months ago)
- Topics: bun, hono, html-to-pdf, puppeteer
- Language: TypeScript
- Homepage: https://html-to-pdf-psi.vercel.app
- Size: 61.5 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTML-To-PDF
## How to Run
_Migrating Bun to Nodejs_
This project build on bun runtime environment. if you need this project on nodejs , you need migrate to Nodejs.
- Step - 1 : Install required dependency for hono (Backend)
```
make bun-to-node
```
- Step - 2 : You need change `index.ts` file in `api/src`. (Follow instructions on that file)
_Setup_
```typescript
// Bun
make setup
// Node js
make setup-node
```
_Start Servers_
```typescript
// Bun
make dev
// Node js
make dev-node
```
Use can serve on `http://localhost:9000`
## Usage
_With fetch_
```typescript
const downloadPDF = async () => {
const res = await fetch("http://localhost:9000/pdf", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Response-Type": "blob",
},
body: JSON.stringify({ html: html }),
});
const blob = await res.blob();
const url = window.URL.createObjectURL(new Blob([blob], { type: "application/pdf" }));
const link = document.createElement("a");
link.href = url;
link.setAttribute("target", "_blank");
document.body.appendChild(link);
link.click();
};
```
_With axios_
```typescript
const downloadPDF = async () => {
await axios
.post(
"http://localhost:9000/pdf",
{ html: html },
{
responseType: "blob",
}
)
.then((res) => {
const url = window.URL.createObjectURL(new Blob([res.data], { type: "application/pdf" }));
const link = document.createElement("a");
link.href = url;
link.setAttribute("target", "_blank");
document.body.appendChild(link);
link.click();
});
};
```
If You face any colour missing issue in generated pdf, You can use below css code in your style sheet.
```css
html {
-webkit-print-color-adjust: exact;
}
```
## License
MIT
## Author
[Kavindu Manahara](https://github.com/kavindu-mane)