I`m using weasyprint by aquavitae for generating PDFs for my Laravel application via cURL
curl -X POST \
-H Content-Type:text/html \
-T ./test.html http://127.0.0.1:5001/pdf?filename=test.pdf \
-o test.pdf
This is an example of cURL request to a weasyprint which gives me a good responce, but when u try to do this in my PHP:
$path_to_file = 'd:/index.html';
$ch = curl_init();
$headers = array(
"Content-Type:text/html"
);
curl_setopt($ch, CURLOPT_URL, 'http://192.168.99.100:5001/pdf');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'datafile' => curl_file_create($path_to_file , mime_content_type($path_to_file), basename($path_to_file))
]
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
I get my responce as a line and when I want to responce it to a browser or into a file I get some information about HTML file I sent: PDF file I get with PHP cURL
tho my HTML file contains only
<h1>hello world</h1>
I can see something like that when I use Postman too. I think that there`s some difference beetwen how I send file with CMD cURL and PHP cURL. Do you guys have any ideas?