0
私のlaravelコントローラにpdfを生成するサンプルコードを書きました。それは200の応答コードを得るが、pdfは生成されない。laravelコントローラでpdfを生成できません
以下は私のコードです。
function exportPDF() {
// instantiate and use the dompdf class
$dompdf = new PDF();
$dompdf->loadHtml('<h1>hello world</h1>');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
return $dompdf->stream();
}
しかし、これは私が直接web.phpファイル内のルート内のコードが含まれている場合に取り組んでいます。
Route::get('/generate-pdf', function() {
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();
});
EDITED
web.php
Route::post('/report-audit-export-pdf', '[email protected]');
の.js
window.exportPDF = function() {
var hidden_category = $('#hidden_category').val();
$.ajax({
type: "POST",
url: '/report-audit-export-pdf',
data: {
},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("jqXHR : " + jqXHR + " and textStatus : " + textStatus + " and errorThrown : " + errorThrown);
},
success: function(content) {
// alert("Success");
}
});
}
私は、問題が何であるかを知っているかもしれませんか?
のようなAJAXリクエストから成功応答を使用することができますので、それはあなたのルートとは何かを持っているアンカー
を使用し、コントローラ機能イオン名。コントローラを使用しているときの初期ルートを表示します。 – EddyTheDove
@EddyTheDove私の投稿を編集しました。見てください。ありがとう! – etzzz
あなたはajax経由でpdfを作成していますか? –