vnotex / vnote

A pleasant note-taking platform in native C++.
https://app.vnote.fun
GNU Lesser General Public License v3.0
11.77k stars 1.21k forks source link

使用wkhtmltopdf导出pdf时,代码块遇分页时出现问题 #933

Open marryton007 opened 5 years ago

marryton007 commented 5 years ago

OS Version (操作系统): Windows, Linux, macOS windows VNote Version (Help - About VNote - Version: )(VNote版本): 2.2, d78e892d5cc etc.. 2.7.2 Symptoms (表现): image

输出日志:

导出到 D:/Documents/vnote_exports 。 使用wkhtmltopdf (0)。 正在导出笔记 D:/Documents/vnote_notebooks/vnotebook/mfc/mfc.md 。 wkhtmltopdf --page-size A4 --orientation Portrait --margin-bottom 10mm --margin-left 10mm --margin-right 10mm --margin-top 16mm --encoding utf-8 --background --javascript-delay 10000 toc --toc-text-size-shrink 1.0 Z:\TEMP\VNote-9jMXMN\vnote_tmp.html D:\Documents\vnote_exports\mfc_001.pdf
...... 笔记 D:/Documents/vnote_notebooks/vnotebook/mfc/mfc.md 导出为 D:/Documents/vnote_exports/mfc_001.pdf 。 导出了 1 个笔记。

PDF效果图: image

How to Repro (如何复现): 使用wkhtmltopdf方式导出pdf格式,如最上图所示

tamlok commented 5 years ago

CSS样式里面有什么设置是可以设置一个元素不能跨页的吗?

marryton007 commented 5 years ago

看了这个连接, 里面有这一段描述,

    page-break-before: always;
    page-break-after: always;
    page-break-inside: avoid;

但这个不知道加在vnote的哪个地方?

tamlok commented 5 years ago

配置文件夹,v_pure.css

marryton007 commented 5 years ago

加在哪个元素下? pre? code? 还是pre code?

tamlok commented 5 years ago

pre试试

marryton007 commented 5 years ago

测试了以下方式,都不行。

code { font-family: Consolas, Monaco, Monospace, Courier; color: #8E24AA; word-break: break-all; page-break-before: always; page-break-after: always; page-break-inside: avoid; }


* common.css

```css
@media print {
    pre, pre code, td.hljs-ln-code {
        white-space: pre-wrap !important;
        word-break: break-all !important;
        page-break-inside: avoid  !important;   
    }

    code, a {
        word-break: break-all !important;
        page-break-inside: avoid  !important; 
    }

另外,不使用wkhtmltopdf导出的PDF是正常的,还有使用打印功能打出的PDF文件也是正常的。

现在的问题是只有wkhtmltopdf导出有问题。