2012-07-18 100 views

回答

2

好的我找到了使用wkhtmltopdf 0.11的方法。我提取的前兩頁到一個獨立的HTML文件,然後運行它像這樣

wkhtmltopdf [options] page cover.html toc --xsl-style-sheet ... input_file.html out.pdf 

不幸的是,花了比我預想的多得多的努力,因爲我用它在Rails應用程序通過wicked_pdf,並且它對新的選項格式不太好,所以我不得不分叉它並進行必要的更改。

通過wicked_pdf生成的命令行看起來是這樣的(略長路徑):在「......」你有你的網頁提取

"c:/program files (x86)/wkhtmltopdf/wkhtmltopdf.exe" 
    --header-html "file:///path/to/header" --footer-html "file:///path/to/footer" 
    --margin-top 20 --margin-bottom 15 --margin-left 5 --margin-right 40 page "file:///path/to/cover/page" --disable-javascript toc --xsl-style-sheet "path/to/style/sheet" - - 
+0

這是否意味着?是否有可能看到使用的實際命令? 「page」指令對我來說並不熟悉。對我來說,就像「把頁面cover.html,然後toc,然後input_file.html和打印out.pdf」,但我懷疑它不是這樣嗎?好的問題,並很好地找到了答案 – Nenotlep 2012-07-20 10:55:43

+1

我相信這個'頁面'和'toc'對象的符號是在v0.10附近引入的。 wkhtmltopdf將這些對象按命令行中給出的順序放入輸出中。 ......實際上是XSL工作表的路徑,抱歉沒有明確說明。我添加了wicked_pdf在我的應用程序中生成的CLI。 – HargrimmTheBleak 2012-07-20 11:53:57

+0

說簡單,你可以有多個* page *對象以及* cover *和* toc *對象。我使用了相同的技巧=而不是使用* cover *,這很難設置頁眉/頁腳,我使用單頁作爲封面,然後是toc,然後是我的文檔的其餘部分,所以'[page] [toc] [page]'vs'[cover] [toc] [page]' – frequent 2016-02-22 15:39:56