這個(gè)工具認(rèn)識(shí)很多年了籽慢,之前用來(lái)把某一個(gè)中文博客轉(zhuǎn)成pdf在kindle上看浸遗。最開(kāi)始只支持windows平臺(tái)费封,現(xiàn)在已經(jīng)支持macos等其他平臺(tái):
一短曾、基本用法
# 轉(zhuǎn)換所有xhtml為pdf
prince --page-size=a6 *.xhtml -o all.pdf
二掀序、添加頁(yè)碼和頁(yè)眉
@page {
@bottom-center {
content: counter(page); # 頁(yè)碼
font-size: 8pt; # 頁(yè)碼字號(hào)
}
@top-center {
content: element(header) ; # 頁(yè)眉
font-size: 8pt; # 頁(yè)眉字號(hào)
}
}
h2 > * {
position: running(header); # 頁(yè)眉內(nèi)容
}
三饲宛、標(biāo)題計(jì)數(shù)器和內(nèi)容分離
原始的xhtml:
<h2><span class="counter">第一章</span>測(cè)試</h2>
修改為:
<h2><span class="counter">第一章</span><span>測(cè)試</span></h2>
上面的內(nèi)容可解析為:firstchild和lastchild璧针,即實(shí)現(xiàn)了計(jì)數(shù)器和內(nèi)容的分離虽画。
@page {
@bottom-center {
content: counter(page);
font-size: 8pt;
}
@top-left {
font-size: 8pt;
font-family: sans-serif;
content: string(term, first);
}
@top-right {
font-size: 8pt;
font-family: sans-serif;
content: string(chapter-title);
}
}
h2 :first-child {
string-set: term content() ;
}
h2 :last-child {
string-set: chapter-title content();
}
四婚肆、設(shè)置頁(yè)面
prince --page-margin=10mm --page-size=a6
命令行幫助:
Usage:
prince [OPTIONS] doc.html Convert doc.html to doc.pdf
prince [OPTIONS] doc.html -o out.pdf Convert doc.html to out.pdf
prince [OPTIONS] FILES... -o out.pdf Combine multiple files to out.pdf
General Options:
-h, --help Display usage and options.
--version Display version information.
--credits Display credits and acknowledgements.
Logging Options:
-v, --verbose Log informative messages.
--debug Log debug messages.
--log=FILE Append log messages to a file.
--no-warn-css Do not warn about CSS (implies the following).
--no-warn-css-unknown Do not warn about unknown CSS features.
--no-warn-css-unsupported Do not warn about unsupported CSS features.
--structured-log=TYPE Enable structured logging on stderr.
[normal|quiet|progress|buffered]
Input Options:
-i, --input=FORMAT Set input format. [xml|html|auto]
-l, --input-list=FILE Read input file list from specified file.
--baseurl=URL Specify the base URL of the input document.
--remap=URL=DIR Map URL prefix to a local directory.
--fileroot=DIR Specify the root directory for absolute filenames
(deprecated).
--iframes Enable HTML iframes.
--xinclude Enable XInclude processing and --xml-external-entities.
--xml-external-entities Enable XML external entities (XXE) and external DTDs.
--no-local-files Disable access to local files.
Network Options:
--no-network Disable network access (prevents HTTP downloads).
--auth-user=USER Specify username for HTTP authentication.
--auth-password=PASS Specify password for HTTP authentication.
--auth-server=SERVER Only send USER:PASS to this server.
--auth-scheme=SCHEME Only send USER:PASS for this scheme. [http|https]
--auth-method=METHODS Specify HTTP authentication methods.
[basic,digest,ntlm,negotiate]
--auth=URL Specify URL with user:pass@server for
authentication.
--no-auth-preemptive Do not authenticate with named servers until
asked.
--http-proxy=PROXY Specify the HTTP proxy server.
--http-timeout=SEC Specify the HTTP timeout in seconds.
--cookie=COOKIE Specify a Set-Cookie header value.
--cookie-file=FILE Specify a file containing HTTP cookies.
--ssl-cacert=FILE Specify an SSL CA certificate file.
--ssl-capath=PATH Specify an SSL CA certificate directory.
--ssl-cert=FILE Specify an SSL client certificate file.
--ssl-cert-type=TYPE Specify the SSL client certificate file type. [pem,der]
--ssl-key=FILE Specify an SSL private key file.
--ssl-key-type=TYPE Specify the SSL private key file type. [pem,der]
--ssl-key-password=PASS Specify passphrase for the private key.
--ssl-version=VERSION Specify an SSL/TLS version to use.
--insecure Disable SSL verification (not recommended).
--ssl-no-revoke Disable certificate revocation checks (Windows).
--ssl-revoke-best-effort Ignore missing/offline CRL distribution points (Windows).
--no-redirects Do not follow HTTP/HTTPS redirects.
--no-parallel-downloads Disable parallel downloads.
JavaScript Options:
-j, --javascript Enable JavaScript in HTML documents.
--script=FILE Run an external script.
--max-passes=NUM Maximum number of times that JavaScript may
modify the document and repeat layout.
CSS Options:
-s, --style=FILE Apply an external style sheet.
--media=MEDIA Specify the media type (eg. print, screen).
--page-size=SIZE Specify the page size (eg. A4).
--page-margin=MARGIN Specify the page margin (eg. 20mm).
--no-author-style Ignore author style sheets.
--no-default-style Ignore default style sheets.
PDF Output Options:
-o, --output=FILE Specify the output PDF filename.
--pdf-profile=PROFILE Specify the PDF profile to use.
--pdf-output-intent=ICC Specify the output intent ICC profile.
--pdf-script=FILE Include an AcroJS script to run when the PDF is opened.
--pdf-event-script=EVENT:FILE Include an AcroJS script to run on a specific event.
[will-close, will-save, did-save, will-print, did-print]
--attach=FILE Attach a file to the PDF.
--tagged-pdf Produce tagged PDF.
--pdf-forms Enable generation of interactive form fields by default.
--no-artificial-fonts Disable synthesis of missing bold/italic fonts.
--no-embed-fonts Disable font embedding in PDF output.
--no-subset-fonts Disable font subsetting in PDF output.
--force-identity-encoding Use identity encoding for all fonts.
--no-compress Disable compression of PDF output.
--no-object-streams Disable use of PDF object streams.
--convert-colors Convert colors to output intent color space.
--fallback-cmyk-profile=ICC Set fallback ICC profile for uncalibrated CMYK.
PDF Metadata Options:
--pdf-lang=LANG Specify the primary language.
--pdf-xmp-metadata Include HTML metadata as XMP in the PDF.
--pdf-xmp=FILE Include additional XMP metadata in the PDF.
--pdf-title=TITLE Set PDF document title.
--pdf-subject=SUBJECT Set PDF document subject.
--pdf-author=AUTHOR Set PDF document author.
--pdf-keywords=KEYWORDS Set PDF document keywords.
--pdf-creator=CREATOR Set PDF document creator.
PDF Encryption Options:
--encrypt Encrypt PDF output.
--key-bits=NUM Set encryption key size [40|128].
--user-password=PASS Set PDF user password.
--owner-password=PASS Set PDF owner password.
--disallow-print Disallow printing of PDF output.
--disallow-modify Disallow modification of PDF output.
--disallow-copy Disallow copying from PDF output.
--disallow-annotate Disallow annotation of PDF output.
--allow-copy-for-accessibility Allow copying content for accessibility.
--allow-assembly Allow document assembly.
Raster Output Options:
--raster-output=TEMPLATE Enable raster output.
--raster-format=FORMAT Set raster output format. [auto|png|jpeg]
--raster-jpeg-quality=NUM Set quality for raster JPEG output.
--raster-pages=PAGE Set range of pages to rasterise. [all|first|NUM]
--raster-dpi=DPI Set resolution of raster output.
--raster-background=COLOR Set background color. [white|transparent]
--raster-threads=NUM Set number of threads for raster output.
Fail-Safe Options:
--fail-safe Set all of the following fail-safe options.
--fail-dropped-content Fail if any content is dropped.
--fail-missing-resources Fail if any resources cannot be loaded.
--fail-missing-glyphs Fail if glyphs cannot be found for any characters.
--fail-stripped-transparency Fail if any transparency is stripped.
--fail-pdf-profile-error Fail if unable to comply with the PDF profile.
--fail-pdf-tag-error Fail if there are problems tagging the PDF.
Utility Options:
--scanfonts FILES... Scan font files and create a CSS file.
--control Communicate via the control interface.
For more information, visit http://www.princexml.com
命令 | 參數(shù) | 輸出 | 解釋 |
---|---|---|---|
prince | [OPTIONS] | doc.html | Convert doc.html to doc.pdf |
prince | [OPTIONS] | doc.html -o out.pdf | Convert doc.html to out.pdf |
prince | [OPTIONS] | FILES... -o out.pdf | Combine multiple files to out.pdf |