0

PDFKitとwkhtmltopdfをインストールしました。

1 つのアクションで、次のような単純な html をレンダリングします。

<html><body><h1>Hello Internet!</h1></body></html>

アクションを .pdf 拡張子で実行すると、間違った pdf ファイルが生成されます。PDFKit のデバッグ 次の行に到達しました。

result = IO.popen(invoke, "w+") do |pdf|
  pdf.puts(@source.to_s) if @source.html?
  pdf.close_write
  pdf.gets(nil)
end

これは、私の PDF が生成される場所です。コマンド ライン no wkhtmltopdf と私の html を入力として使用します。

rdebug を使用すると、invoke の値は次のようになることがわかりました。

"c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-"

そして @source.to_s は

<html><body><h1>Hello Internet!</h1></body></html>

わかりましたので、次のように手動でコマンドを実行しようとしました:

"c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-" < c:\hello_internet.html > correct.pdf

明らかに、hello_internet には @source.to_s のコンテンツがあります。

実行すると、正しい pdf が生成されます。

生成された正しい pdf はhereで、間違った pdf はhereです。

ここで何が問題なのかわかりません。

ありがとう。

4

1 に答える 1

0

ソリューションは非常にシンプルで、PDFKits Github の bxu689 によるプル リクエストの対象です。

于 2011-03-29T21:55:59.193 に答える