Reputation: 101
I use html2pdf to generate pdf from a wordpress post (inside a multi site install), it's working great I have the following setup:
on my homepage I have a link
<a target="_blank" id="downloadPDF" href="<?php echo get_template_directory_uri(); ?>/pdf_processor.php?blogid=<?php echo get_current_blog_id(); ?> ">download</a>
and on my pdf_processor.php the pdf is generated as espected and i use `
$html2pdf->Output('exemple.pdf', 'D');
using 'D' allow to download the pdf directly which is what i want.
now I would like to generate the pdf whith an ajax call (so i can display a loading icone while waiting), I already tryed setting up an ajax call with jquery that posts the get_current_blog_id();
to pdf_processor.php
, i don't know how to handle the response so that when the ajax call is a success $html2pdf->Output('exemple.pdf', 'D');
is triggered, on my atempt i tried
echo $html2pdf->Output('exemple.pdf', 'D');
but that just returns a strange string.
Upvotes: 0
Views: 4460
Reputation: 366
Use 'F' to save the file on server and then open up the file. 'D' is always going to return some unreadable string if you try to alert it through javascript.
$html2pdf->Output('D:\xampp\htdocs\frescoframes12/My-File-Name.pdf','F');
Upvotes: 2