English | 中文
![](https://private-user-images.githubusercontent.com/19891724/266481460-86177762-8a97-4656-8ee0-5add61c50237.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1OTU1NTksIm5iZiI6MTczOTU5NTI1OSwicGF0aCI6Ii8xOTg5MTcyNC8yNjY0ODE0NjAtODYxNzc3NjItOGE5Ny00NjU2LThlZTAtNWFkZDYxYzUwMjM3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDA0NTQxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk1NzEzODYyYjI2OWUwNTMzZGE3YjU2NmZhYjUyODEyMmYxNjQwZjE1MThkYjc0YTRkOWQyYmUwOWQ1OGM5ZDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0._SG_7qIh0XmAXE8hDx2drEpxbe65wQM71l57S7uo-2E)
To experience enhanced features and broader browser support, the entire codebase of the latest version has seamlessly migrated to Playwright.
Playwright repo: koa-playwright-server
🦩 Koa + ESM + TypeScript + Rollup + Nodemon + Puppeteer + ESLint (v9)
Fast Generate into PDF and images from any webpage.
Support merge multiple webpages into one PDF file, injection of Cookies, Watermark addition and Header and Footer insertion
-
✅ Built-in ES Module + TypeScript environment
-
🌈 Separation business logic and Controllers.
-
🛡 Probably the best practice for Puppeteer project.
-
🧩 Configured routing.
-
🚧 Eslint (v9) configuration.
-
⚡ Fast build with Rollup.
-
🔌 Extensible PDF watermark, header and footer.
-
🧲 Supports merging of multiple PDF files.
-
🔥 Based on Nodemon HMR.
- Merge Combine the two websites into a PDF file
📦 See Merge Test 1, Merge Test 2
Please make sure that Node.js (>= 20.x) is installed on your operating system.
├── src │ ├── controllers/ --- Server controllers │ ├── services/ --- Server services │ ├── config.ts --- About Environments variable │ ├── main.ts --- Entry file │ └── routes.ts --- Configs for routing controllers 👉 Routing
pnpm install
pnpm dev
The project has built-in a pm2
, running the pnpm start
will automatically manage the process by pm2
.
Run pnpm build
to build, then run pnpm start
to start the process managed by pm2
:
- Build
pnpm build
- Run
pnpm start # PORT is 8080
# or
node dist/bundle.esm.js # PORT is 5000
GET /image
Generate screenshot.
curl --location --request GET \
'http://localhost:5000/image?url=https://www.baidu.com' \
--output test-image.png
GET /simple-pdf
Generate pdf.
curl --location --request GET \
'http://localhost:5000/simple-pdf?url=https://www.google.com/' \
--output test-simple-pdf.pdf
POST /pdf
Generate pdf with elements such as headers and footers.
curl --location --request POST 'http://localhost:5000/pdf' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'url=http://www.google.com' \
--data-urlencode 'cookies[0].name=token' \
--data-urlencode 'cookies[0].value=9s2d4c16-f072-16eg-b134-0642ap190006' \
--data-urlencode 'cookies[0].domain=www.google.com' --output test-complex-pdf.pdf
👆 /pdf request parameters
Field | Description | Type | Default Value |
---|---|---|---|
url | Target site url | string | — |
cookies | Generally used as a website that requires login to access, you can add this field | Array<{ name, value, domain }> | [] |
hasMargin | If this field is set to true, it means that the generated PDF will contain margins | boolean | true |
isLandscape | Whether the generated PDF is horizontal | boolean | false |
hiddenWatermark | Whether to hide watermark | boolean | false |
attachment | Display the custom header and footer, provided that hasMargin is set to true | { header, footer } | — |
POST /combine-pdf
Merge multiple PDF files into one file.
See Merge Test 1, Merge Test 2
👆 /combine-pdf request parameters
Field | Description | Type | Default Value |
---|---|---|---|
pdfList | A collection of target websites, the parameter type is an array, and each item in the array is a parameter required by /pdf |
Array<{ pdfItem }> | [] |
In order to make the routing information more readable and transparent, the form of configuration is adopted here.
You can create an array
and then write the routing meta information into the array
, and reuse it in the src/routes.ts
const routes: Array<RouteConfig> = [
{
path: '/',
method: 'get',
action: homeController.hello
},
// here...
]
✌️