php/golang使用chrome内核实现服务器端html转pdf,html转图片,pdf加水印,pdf转图片等
Doctron
Doctron是一个docker化的文档转换工具,在线演示地址:Doctron。github地址: https://github.com/lampnick/doctron 。 有如下特点:
- html转图片(支持自定义页面大小,边距,高质量转换)
- html转pdf(支持自定义页面大小,边距,高质量转换)
- pdf加水印
- 服务器端渲染
- 一键部署(支持docker,提供了k8s yaml配置文件)
- serverless
Table of Contents
- Features
- Deploy
- Quick Start
- Html convert to pdf
- Html convert to image
- Pdf add watermark
- Pdf convert to image[not implement,arriving soon]
- Doctron Client
- Doctron go client
- Doctron php client
- License
Features
- Html convert to pdf/image using chrome kernel to guarantee what you see is what you get.
- Easy deployment.(Using docker,kubernetes.)
- Rich transformation parameters.
- Customize page size from html convert to pdf or image.
- Serverless supported.
Installing
- Using docker
1 2 3 4 5 6 | #using default config docker run -p 8080:8080 --rm --name doctron-alpine lampnick/doctron #using custom config docker run -p 8080:8080 --rm --name doctron-alpine \ -v /path/to/doctron/conf/doctron.yaml:/doctron.yaml \ lampnick/doctron |
- Using k8s
1 | kubectl apply -f https://github.com/lampnick/doctron/manifests/k8s-doctron.yaml |
- From source code
1 2 3 | git clone https://github.com/lampnick/doctron.git cd doctron go run main.go |
Quick Start
Html convert to pdf
basic
1 | http://127.0.0.1:8080/convert/html2pdf?u=doctron&p=lampnick&url=<url> |
custom size
1 | http://127.0.0.1:8080/convert/html2pdf?u=doctron&p=lampnick&url=<url>&marginTop=0&marginLeft=0&marginRight=0&marginbottom=0&paperwidth=4.1 |
support params
- u/username // doctron username
- p/password // doctron password
- uploadKey // upload to oss key
- url // need convert html url
- landscape // Paper orientation. core.Defaults to false.
- displayHeaderFooter // Display header and footer. core.Defaults to false.
- printBackground // Print background graphics. core.Defaults to false.
- scale // Scale of the webpage rendering. core.Defaults to 1.
- paperWidth // Paper width in inches. core.Defaults to 8.5 inches.
- paperHeight // Paper height in inches. core.Defaults to 11 inches.
- marginTop // Top margin in inches. core.Defaults to 1cm (~0.4 inches).
- marginBottom // Bottom margin in inches. core.Defaults to 1cm (~0.4 inches).
- marginLeft // Left margin in inches. core.Defaults to 1cm (~0.4 inches).
- marginRight // Right margin in inches. core.Defaults to 1cm (~0.4 inches).
- pageRanges // Paper ranges to print, e.g., ‘1-5, 8, 11-13’. core.Defaults to the empty string, which means print all pages.
- ignoreInvalidPageRanges // Whether to silently ignore invalid but successfully parsed page ranges, such as ‘3-2’. core.Defaults to false.
Html convert to image
basic
1 | http://127.0.0.1:8080/convert/html2image?u=doctron&p=lampnick&url=<url> |
custom size
1 | http://127.0.0.1:8080/convert/html2image?u=doctron&p=lampnick&url=<url>&customClip=true&clipX=0&clipY=0&clipWidth=400&clipHeight=1500&clipScale=2&format=jpeg&Quality=80 |
support params
- u/username // doctron username
- p/password // doctron password
- uploadKey // upload to oss key
- url // need convert html url
- format // Image compression format (defaults to png).
- quality // Compression quality from range [0…100] (jpeg only).
- customClip //if set this value, the below clip will work,otherwise not work!
- clipX // Capture the screenshot of a given region only.X offset in device independent pixels (dip).
- clipY // Capture the screenshot of a given region only.Y offset in device independent pixels (dip).
- clipWidth // Capture the screenshot of a given region only.Rectangle width in device independent pixels (dip).
- clipHeight // Capture the screenshot of a given region only.Rectangle height in device independent pixels (dip).
Pdf add watermark
add image watermark
1 | http://127.0.0.1:8080/convert/pdfAddWatermark?u=doctron&p=lampnick&url=<pdf url>&imageUrl=<image url> |
support params
- u/username // doctron username
- p/password // doctron password
- uploadKey // upload to oss key
- url // need convert html url
- imageUrl // watermark image url,support png/jpeg