PDFKIT使用css禁用部分class导致白边的处理
通过设置CSS和pdfkit的选项来处理(测试有效)
必须安装wkhtmltopdf https://wkhtmltopdf.org/downloads.html
1 |
|
如果还有白边,可以尝试以下方法:
1.直接在HTML中添加内联样式
1 |
|
使用自定义纸张大小(测试有效)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15options = {
'margin-top': '0',
'margin-right': '0',
'margin-bottom': '0',
'margin-left': '0',
'page-width': '210mm',
'page-height': '297mm',
'disable-smart-shrinking': '',
'zoom': '1.0', # 可以调整缩放比例
'custom-header': [
('Accept-Encoding', 'gzip')
],
'no-outline': None,
'encoding': 'UTF-8'
}如果是特定元素的白边
1
2
3
4
5
6
7
8
9
10
11
12
13/* 针对特定容器 */
.container {
margin: 0 !important;
padding: 0 !important;
width: 100% !important;
max-width: none !important;
}
/* 确保图片等内容不会溢出 */
img {
max-width: 100%;
height: auto;
}
PDFKIT使用css禁用部分class导致白边的处理
https://more678.github.io/2025/02/01/PDF白边解决方式/