# pdf-service **Repository Path**: hxr521521/pdf-service ## Basic Information - **Project Name**: pdf-service - **Description**: 使用node + headless 来将html转成pdf, 提供了2个api 一个是通过url转pdf 一个是挂载目录模版来然后 调用url传入json 来导出pdf - **Primary Language**: NodeJS - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-15 - **Last Updated**: 2025-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 说明 ## 构建指令 ``` docker build -t pdf-service . ``` ## 启动指令 ``` docker run -d --name pdf-service -p 3000:3000 -v $(pwd)/templates:/app/templates pdf-service 生产强烈建议 增加内存参数--shm-size=1g 并发越高 需要的越大。。。 docker run -d --shm-size=1g --name pdf-service -p 3000:3000 -v $(pwd)/templates:/app/templates pdf-service ``` ## 测试 ``` 可以引入 css js img 模版内不要使用相对路径 可以直接使用模版内部的路劲引入 例如 http://localhost:3000/templates/vue.js 会将json注入到 便签之下 json的引用 是 window.__PDF_DATA__ curl -X POST http://localhost:3000/generate-pdf \ -H "Content-Type: application/json" \ -d '{"template":"paper2","data":{"title":"测试555"}}' \ --output test5.pdf curl -X POST http://localhost:3000/url-to-pdf \ -H "Content-Type: application/json" \ -d '{ "url": "http://localhost:3000/templates/testvue.html", "pdfOptions": { "format": "A4" } }' --output output.pdf ```