{"id":43873695,"url":"https://github.com/haust-lyb/html2pdf","last_synced_at":"2026-02-06T14:38:14.703Z","repository":{"id":51371493,"uuid":"327276607","full_name":"haust-lyb/html2pdf","owner":"haust-lyb","description":"利用wkhtmltopdf，提供PDF生成的解决方案","archived":false,"fork":false,"pushed_at":"2024-07-24T10:16:57.000Z","size":17991,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-25T10:00:20.276Z","etag":null,"topics":["html2pdf"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haust-lyb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-06T10:28:04.000Z","updated_at":"2024-07-24T10:17:01.000Z","dependencies_parsed_at":"2024-07-24T10:12:19.706Z","dependency_job_id":null,"html_url":"https://github.com/haust-lyb/html2pdf","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/haust-lyb/html2pdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haust-lyb%2Fhtml2pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haust-lyb%2Fhtml2pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haust-lyb%2Fhtml2pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haust-lyb%2Fhtml2pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haust-lyb","download_url":"https://codeload.github.com/haust-lyb/html2pdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haust-lyb%2Fhtml2pdf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29164921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T14:37:12.680Z","status":"ssl_error","status_checked_at":"2026-02-06T14:36:22.973Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html2pdf"],"created_at":"2026-02-06T14:38:14.541Z","updated_at":"2026-02-06T14:38:14.695Z","avatar_url":"https://github.com/haust-lyb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html2pdf文档\n\n## 一、how to use\n\n### 1、run with docker \n\n```shell\ndocker run --name html2pdf -p 16666:16666 -v /Users/makabaka/html2pdf:/app/html2pdf -d liyibo888/html2pdf:v1\n```\n\nopen browser http://localhost:16666/html2pdf \n\nadd template\n\n![img.png](img.png)\n\nthen send rest request to generate pdf\n\n## rest api to generate a pdf\n\nGET http://localhost:16666/html2pdf/generatePDFAndDownload\n\n\u003e Request Body 请求参数\n\n```json\n{\n  \"templateId\": \"string\",\n  \"jsonData\": \"string\"\n}\n```\n\n### 请求参数\n\n|名称|位置|类型|必选|说明|\n|---|---|---|---|---|\n|body|body|object| 否 |none|\n|» templateId|body|string| 是 |none|\n|» jsonData|body|string| 是 |none|\n\n\u003e Request Body Example\n\n```json\n{\n  \"templateId\": \"1791005091357134848\",\n  \"jsonData\": \"{\\\"applyHospitalName\\\":\\\"市人民医院\\\"}\"\n}\n```\n\n### 返回结果\n\nPDF file\n\n![img_1.png](img_1.png)\n\n### 2、run with local [有点难，不推荐]\n\n#### 1.1 安装使用步骤概览\n\n![image](https://user-images.githubusercontent.com/23397828/117279085-edeba100-ae93-11eb-819d-a4ac5568c758.png)\n\n\n#### 1.2 详细安装教程（其实也非常简单，对于学过springboot的同学来说看1.1足够了）\n\n待补充。。。。\n\n##### 1.2.1 安装htmltopdf\n\n这里我们以centos7为例\n首先去htmltopdf官网(https://wkhtmltopdf.org/downloads.html) ,下载centos7版本的rmp包。\n![image](https://user-images.githubusercontent.com/23397828/117391215-13bf8700-af22-11eb-8242-dd2994d94cdd.png)\n将下载的rmp包上传到服务器的/usr/local/html2pdf/source目录中，您也可以选择其他目录\n```\n[root@telemedicine-srv02 source]# ls\nwkhtmltox-0.12.6-1.centos7.x86_64.rpm\n[root@telemedicine-srv02 source]# pwd\n/usr/local/html2pdf/source\n```\n进入到source目录执行命令 \n```\nrpm -ivh wkhtmltox-0.12.6-1.centos7.x86_64.rpm \n```\n发现缺少一些依赖，直接使用yum安装即可\n![image](https://user-images.githubusercontent.com/23397828/117391725-225a6e00-af23-11eb-8cb8-d6547c9b5b54.png)\n```\nyum install xorg-x11-fonts-Type1\nyum install xorg-x11-fonts-75dpi\n```\n之后再次执行安装命令即可安装成功\n```\nrpm -ivh wkhtmltox-0.12.6-1.centos7.x86_64.rpm \n```\n![image](https://user-images.githubusercontent.com/23397828/117391964-ac0a3b80-af23-11eb-86cf-7a25b5a67d23.png)\n查看安装位置\n![image](https://user-images.githubusercontent.com/23397828/117392121-04413d80-af24-11eb-9704-7aec86404ec1.png)\n配置环境变量\n以.bash_profile为例`vim ~/.bash_profile`\n追加`PATH=$PATH:/usr/local/bin`\n别忘了保存后`source ~/.bash_profile`\n测试wkhtmltopdf的可用性，此处以百度首页为例\n`wkhtmltopdf https://www.baidu.com ./baidu.pdf`\n\n![image](https://user-images.githubusercontent.com/23397828/117392628-0c4dad00-af25-11eb-84ee-74230406b364.png)\n\n如果你打开这个图片大概率会看到中文是无法显示的，因为centos7里面没有相关的字体\n\n解决方案：\n\n复制windows计算机中C:\\Windows\\Fonts\\simsun.ttc(宋体)，上传到服务器 /usr/share/fonts/chinese/TrueType/simsun.ttc\n\n对于找不到simsun.ttc的同学，可以点击这里的链接直接下载：simsun.ttc快速下载链接：https://github.com/haust-lyb/html2pdf/files/6438836/SIMSUN.TTC.zip 下载后需要解压使用\n\n再试试`wkhtmltopdf https://www.baidu.com ./baidu.pdf`发现成功显示了中文\n\n![image](https://user-images.githubusercontent.com/23397828/117394667-1ffb1280-af29-11eb-85c6-7aebd11ac1f2.png)\n\n到此wkhtmltopdf安装完毕\n\n\n## 二、架构图\n\nbeetl模板渲染，wkhtml2pdf根据模板和数据的渲染结果生成pdf文件\n![image](https://user-images.githubusercontent.com/23397828/117278305-39ea1600-ae93-11eb-9696-425ab180b637.png)\n\n\n## 三、扩展或更改\n\n待补充\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaust-lyb%2Fhtml2pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaust-lyb%2Fhtml2pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaust-lyb%2Fhtml2pdf/lists"}