Hello,
After the data is saved in database I am generating PDF with below ajax code
I do not have any problem here.
$.ajax({
type: "GET",
url: "dompdf/create_pdf.php",
data: {"create_pdf_id" : <?php echo $lastInsertId; ?>},
success: function(msg){
});
I download the previously created pdf file from the list of data saved on a page in the administration panel with the following code
I do not have any problem here.
<a target="_blank" href="../download_pdf.php?pdf_id=188">PDF</a>
if(isset($_GET['pdf_id'])){
$sql = $pdo->prepare("SELECT * FROM table WHERE id=? ");
$sql->execute([$_GET['pdf_id']]);
$read = $sql->fetch();
ob_start();
$pdfdosyatarih = $read['pdf_file_name'];
$pdfdosyatarihi = substr($pdfdosyatarih,0,16);
$dosya = PDFDIR."/".$read['pdf_file_name'];
$islem = fopen($dosya, "rb");
$icerik = fread($islem, filesize($dosya));
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
$pdfdosyaadi = "pdf file name ".$pdfdosyatarihi.".pdf";
if(isset($_GET['pdf_id'])){
header('Content-Disposition: attachment; filename='.$pdfdosyaadi.'');
}else{
header('Content-Disposition: filename='.$pdfdosyaadi.'');
}
echo $icerik;
fclose($islem);
ob_end_flush();
}
When the download PDF button I want to do is clicked, if the file does not exist, I want it to re-create the PDF file and download it.
I want to do this without redirecting to any page while doing this.
I would also like to show the message “The PDF File You Want To Download Is Regenerating Because It Does Not Exist. Please Wait. This May Take Some Time” during the process
I have code to show notification message with ajax
// Wait message is shown as soon as the ajax process starts
var bekleme = jw("b bekle").baslik("Please wait......").icerik("The PDF File You Want To Download Is Regenerating Because It Does Not Exist.<br />Please Wait...<br />This May Take Some Time").en(250).boy(120).kilitle().akilliKapatPasif().ac();
$.ajax({
success: function(msg){
bekleme.kapat(); //Wait message closes when successful
}
});
Thank you