This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I am using DynamicPDF and I am opening my file in new tab to generate my file which is working absolutely fine. Here is what I have sone so far (in one of my plugin's update.htm
file).
<a href="<?= url('/'); ?>/regency-brochure" class="btn btn-primary" target="_blank">Preview Brochure</a>
Now I am trying to somehow do the same by opening/downloading the same file via AJAX response. Hence I have put below code inside my update.htm
file.
<button
type="submit"
data-request="onPreview"
data-load-indicator="Loading Preview"
class="btn btn-primary">Preview Brochure Ajax
</button>
And Inside my controller I have done this.
public function onPreview()
{
return PDF::loadTemplate('renatio::invoice')->download('download.pdf');
}
Now as soon as I click on it, my browser getting hanged, but I am able to see some random binary long string in my response.
I have checked and read library's documentation and they are giving a tip saying...
Tip: Download PDF via Ajax response
OctoberCMS ajax framework cannot handle this type of response.
Recommended approach is to save PDF file locally and return redirect to PDF file.
And I tried to open / download by using return
but its not working.
Can someone guide me how can I solve this ? How can I make my PDF file open / download using AJAX here ?
I have implemented this feature. If anyone wants to follow, visit this thread - https://stackoverflow.com/questions/55756920/octobercms-dynamicpdf-open-or-download-via-ajax
Hope this helps.
1-2 of 2