私はjsPDFを見ましたが、プラグインはエクスポートされたPDFのCSSを取り除いています。私もhtml2canvasを見てきましたが、それは現在のウィンドウのスクリーンショットをとります。私のHTMLコンテンツはユーザーから隠されていて、HTMLブロックからその場でPDFを作成するソリューションを探しています。助言がありますか?Javascriptを使用してHTML/CSSをPDFに変換するにはどうすればよいですか?
EDIT: jsPDFにhtml2canvasを作成しようとしましたが、空のPDF文書があります。誰かがなぜ私に教えてくれますか? http://jsfiddle.net/5ud8jkvf/6320/
$('.download').on('click', function(){
html2canvas($('.print'), {
onrendered: function(canvas) {
$('#canvas').replaceWith(canvas);
},
//width: 200,
//height: 200
});
setTimeout(function(){
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
doc.fromHTML($('canvas').html(), 15, 15, {
'width': '200',
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
}, 500);
});
http://stackoverflow.com/質問/ 391005/convert-html-css-to-pdf-with-php – Benjamin
簡単な解決策はありません。 JavaScriptで完全なWebブラウザの半分を実装する必要があります。私はこのプログラムを使ってサーバー上でPDFを生成します:http://wkhtmltopdf.org/。 – Michas