princexml
(重定向自Prince)
免费版会在输出文件的第一页加入一个图标,不会被打印,可使用编辑器删除。
页面设置
@page {
size: a4;
margin: 2cm;
font: 11pt/1.3 "Gentium", serif;
@top-right {
content: string(title);
font-style: italic;
}
@top-left {
content: string(source);
font-style: italic;
}
@bottom-center {
content: counter(page);
vertical-align: top;
padding-top: 1em;
}
}
页面编号
@page main {
@bottom {
content: counter(page) "/" counter(pages);
}
}
body {
page: main;
counter-reset: page 1;
}
分页
在表格内部不要分页:
@media print {
table {
page-break-inside:avoid;
}
}
强制分页:
.pagebreaker {
display: block;
page-break-after: always;
}
Kindle Paperwhite
适合 Kindle Paperwhite 横屏阅读含代码等宽内容:
@page {
size: 18cm 12cm landscape;
margin: 0;
}
网页转单页 PDF
prince page.html --media=screen --page-size='1906px 6342px' --pdf-lang=zh-CN -s fonts.css -o page.pdf
其中,--page-size 的宽度是 document.documentElement.scrollWidth,高度是 document.documentElement.scrollHeight。fonts.css 用来覆盖 prince 自带的字体替换规则,如
@font-face {
font-family: sans-serif;
src: prince-lookup("Source Han Sans")
}
@font-face {
font-family: serif;
src: prince-lookup("Source Han Serif")
}
参见
外部链接
- 官方文档
- https://www.princexml.com/howcome/2008/wikipedia/wiki2.css 官网提供的维基百科的样式表
- Using princexml to generate kindle friendly PDF.(中文)
- Prince XML for creating mobile reader-sized PDFs? - MobileRead Forums