Thank You @sanjay.
@Artem i did it in PHP with Curl:
function erpnext_cmd($host,$array,$cookie){
$ch = curl_init();
$payload = json_encode($array);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_URL, ‘http://’.$host.‘/api/method’);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen($payload)
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$download_array = array(‘cmd’ => ‘frappe.utils.print_format.download_pdf’,‘doctype’ => ‘Delivery Note’,‘name’ => $delivery_id, ‘format’ => ‘DN2’);
$download_data = erpnext_cmd($host ,$download_array,$cookie);
$pdfdata = base64_encode($download_data);
Javascript to download base64_pdf:
function download_pdf(base64Data,filename) {
var arrBuffer = base64ToArrayBuffer(base64Data);
var newBlob = new Blob([arrBuffer], { type: "application/pdf" });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
return;
}
var data = window.URL.createObjectURL(newBlob);
var link = document.createElement('a');
document.body.appendChild(link);
link.href = data;
link.download = filename + ".pdf";
link.click();
window.URL.revokeObjectURL(data);
link.remove();
}
function base64ToArrayBuffer(data) {
var binaryString = window.atob(data);
var binaryLen = binaryString.length;
var bytes = new Uint8Array(binaryLen);
for (var i = 0; i < binaryLen; i++) {
var ascii = binaryString.charCodeAt(i);
bytes[i] = ascii;
}
return bytes;
};
Hope This make sense.
I used this on a site that we hosted : https://www.standertonmills.co.za
gave more details of my dev here: PHP Company Website - #2 by trentmu
In Insomnia i used folowing:
http://your_url/api/method/frappe.utils.print_format.download_pdf?doctype=Sales%20Order&name=SO-00001&format=‘Sales%20Order2’&no_letterhead=0
Have a nice day
Albertus Geyser