0
嘿傢伙我試圖使用html2pdf生成pdf文件,但我無法成功使其工作,因爲我得到一個不可讀的內容 所以基本上我有一個簡單的PHP頁面,生成一個PDF從另一個側面,我有我的服務文件使用html2pdf with angularjs
$content = ob_get_clean();
require_once(dirname(__FILE__).'/../vendor/autoload.php');
try
{
$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 0);
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$html2pdf->createIndex('Sommaire', 25, 12, false, true, 1);
$html2pdf->Output('bookmark.pdf');
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
,他的一些數據發送給它,並得到迴文件是這樣的
this.generatePDF = function (commande) {
var deferred = $q.defer();
$http({
method: 'POST',
//responseType: 'arraybuffer',
url: 'vendor/modules/html2pdf/examples/bookmark.php',
timeout: 15000,
data: $.param({'data': commande}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
//headers: {'Content-Type': 'application/pdf'}
//header :{"Content-Disposition": "attachment; filename=sample.pdf"}
}).then(function successCallback(response) {
debugger;
deferred.resolve(response.data);
}, function errorCallback(response) {
deferred.resolve(response.statusText);
});
return deferred.promise;
};
爲這是控制器端的最後一部分時,用戶presse生成我打電話給我的服務並將數據綁定到它然後得到整個東西回來成功後,並將其寫入到一個新的窗口的內容
var popup = $window.open('', 'TEST', 'width=500,height=900');
ServiceCommande.generatePDF($scope.commande).then(function (data) {
popup.document.write(data);
});
的東西是得到一些奇怪的東西,而不是說我送 strange behavior pdf format
感謝您的PDF^^
這是一個PDF看起來像文本。這不是一個可讀的格式。你可以 - 爲了測試目的 - 把奇怪的東西保存在一個文件結尾* .pdf *並嘗試打開它。你想用你生成的pdf做什麼?如果你想在彈出窗口中顯示它,我想你需要先將它保存爲pdf,然後才能將它加載到你的html中。 – kabaehr
感謝您的快速回復,是啊,這正是我想要它做的我已經將文件保存爲PDF格式,所以而不是發送整個PDF文本我只需要發送文件的當前位置打開是這樣嗎? –