We have kept one button in mass action in orders grid, upon clicking it should generate a PDF file, which is working fine, but after generating PDF the should refresh automatically. That's we are having issues, we are unable to refresh it after generating PDF file.

Actual Problem: Our goal is to generate PDF and refresh the page after PDF is generated. Our PDF is generated properly but after it get download the page is not refreshing.

1) We have tried to put header function of PHP to refresh/redirect. but is not working as header is already set to download data

$name= $this->fileFactory->create(sprintf('manifest_%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),$pdf->render(),DirectoryList::VAR_DIR,'application/pdf');
header("Location: http://google.com");

2) We have set the cookie while downloading the PDF and if cookie is set then we redirect page from JQUERY script with window function. but its not working as it is unable to facth cookie value.

setcookie("redirectCookie", 'test');     
header("Content-Type: application/octet-stream");
$file = "mansi1.pdf";
header("Set-Cookie: fileLoading=true");   
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");     
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
echo fread($fp, 65536);
flush(); // this is essential for large downloads

//jquery code//
setInterval(function(){ console.log($.cookie("redirectCookie"));  if ($.cookie("redirectCookie") )     {        $.removeCookie("redirectCookie");        window.location.href = "http://google.com";    }},1000);
//jquery code//

3) We have called curl url and in that url we have written code to download PDF and if response get true then redirection will be done but this is also not working

//curl called //
$url    = 'url_to_generate_pdf';
$params = array();
$this->_curl->post($url, $params);
$response = $this->_curl->getBody();
//this part not executing //
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect;
//curl called //

Note: We are exporting PDF using headers.

  • Did you find any solution to this?
    – Creepin
    Jul 15 '20 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.