html女器、xhtml轉(zhuǎn)pdf工具princexml試用

這個(gè)工具認(rèn)識(shí)很多年了籽慢,之前用來(lái)把某一個(gè)中文博客轉(zhuǎn)成pdf在kindle上看浸遗。最開(kāi)始只支持windows平臺(tái)费封,現(xiàn)在已經(jīng)支持macos等其他平臺(tái):

下載:https://www.princexml.com/

一短曾、基本用法

# 轉(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

參考

  1. https://www.princexml.com/doc/paged/
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末驳阎,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子郑藏,更是在濱河造成了極大的恐慌衡查,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,248評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件译秦,死亡現(xiàn)場(chǎng)離奇詭異峡捡,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)筑悴,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,681評(píng)論 2 381
  • 文/潘曉璐 我一進(jìn)店門(mén)们拙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人阁吝,你說(shuō)我怎么就攤上這事砚婆。” “怎么了突勇?”我有些...
    開(kāi)封第一講書(shū)人閱讀 153,443評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵装盯,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我甲馋,道長(zhǎng)埂奈,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,475評(píng)論 1 279
  • 正文 為了忘掉前任定躏,我火速辦了婚禮账磺,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘痊远。我一直安慰自己垮抗,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,458評(píng)論 5 374
  • 文/花漫 我一把揭開(kāi)白布碧聪。 她就那樣靜靜地躺著冒版,像睡著了一般。 火紅的嫁衣襯著肌膚如雪逞姿。 梳的紋絲不亂的頭發(fā)上辞嗡,一...
    開(kāi)封第一講書(shū)人閱讀 49,185評(píng)論 1 284
  • 那天,我揣著相機(jī)與錄音滞造,去河邊找鬼欲间。 笑死,一個(gè)胖子當(dāng)著我的面吹牛断部,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播班缎,決...
    沈念sama閱讀 38,451評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼蝴光,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼她渴!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起蔑祟,我...
    開(kāi)封第一講書(shū)人閱讀 37,112評(píng)論 0 261
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤趁耗,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后疆虚,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體苛败,經(jīng)...
    沈念sama閱讀 43,609評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,083評(píng)論 2 325
  • 正文 我和宋清朗相戀三年径簿,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了罢屈。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,163評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡篇亭,死狀恐怖缠捌,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情译蒂,我是刑警寧澤曼月,帶...
    沈念sama閱讀 33,803評(píng)論 4 323
  • 正文 年R本政府宣布,位于F島的核電站柔昼,受9級(jí)特大地震影響哑芹,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜捕透,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,357評(píng)論 3 307
  • 文/蒙蒙 一聪姿、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧激率,春花似錦咳燕、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,357評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至嘉冒,卻和暖如春曹货,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背讳推。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,590評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工顶籽, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人银觅。 一個(gè)月前我還...
    沈念sama閱讀 45,636評(píng)論 2 355
  • 正文 我出身青樓礼饱,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子镊绪,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,925評(píng)論 2 344

推薦閱讀更多精彩內(nèi)容