Hi,
I want to process a PDF file by let the server change the page size and splitting/ cropping the file. For a while it was working by downloading the file to the server using
system('curl --request POST "https://***URL taken from the API" --data "' . $encodeData . '"');
Where $encodeData was generated by utilizing gantt._serialize_HTML(). It was working for 10 times or so and suddenly it is not working any longer. I don’t receive anything anylonger. The funny thing is, when I store $encodeData to a file and run curl from the command line by using
curl --request POST "https://***URL taken from the API" --data "@tmp/gantt_export_6WC8iR.pdftest.txt" >> tmp/test2.pdf
it works like a charm.
The same if I run
system('curl --request POST "https://export.dhtmlx.com/gantt" --data "@' . $fp . '"');
where $fp points to tmp/gantt_export_6WC8iR.pdftest.txt.
Because the data file will blow the view of the post the file can be viewed here https://demo2.owncollab.com/index.php/s/w7jjpIbel1WLyze.
The pdf downloaded via commandline can be viewed here https://demo2.owncollab.com/index.php/s/PODs4uvL9tw4TOu.
What can be the matter, that it was working for a while and suddenly stopped working?
EDIT: Okay, now for a reason I get an “Invalid JSON Data” error. How can I find out where the error happens? The only thing I changed was some tasks.
Thx for help!
Andy
To find out what maybe the difference between the data gantt._send_to_export is sending and curl is sending I stored the data to a file and compared it to the file I generated with my data in php.
The only difference I recognized is that “(” and “)” are encoded to “%28” and “%29” in php. So I replaced them in my php data to look the same like the data in gantt._send_to_export and now the files are exactly the same. But the problem still exists. If I proceed curl from the command line, a pdf file is generated. If I proceed curl from php I only get return “Invalid JSON Data”.
I also recognized, that in the beginning of creating a chart both methods to get the pdf are working. Sometime, if I play around and add links and more tasks the descriped behaviour appears. Can it be, that if the size of the dataset sent matters in a way? It looks that datasets upto a size of 120kB are processed fine on both ways but if they get bigger, they fail.
If somebody is interested, the dataset with the identical files created on different ways is located on https://demo2.owncollab.com/index.php/s/mBB2XQUiqYAkM59
Every help is appreciated.
For whom who might be curious, I found 2 solution:
- storing the data into a file and run
system('curl --request POST "URL from the API" --data "@' . $dataFile . '" >> '.$pdfFile);
- Use the php built-in curl options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "URL from the API");
curl_setopt($ch, CURLOPT_POSTFIELDS, $encodeData);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
file_put_contents($pdfFile, $output);
Both methods seem to work without any problems.
Andy