2
After I save information in the database using the following code.
$this->anamnese->create($input);
I just call to test a code to generate a test PDF with the following code.
PDF::SetTitle('Hello World');
PDF::AddPage();
PDF::Write(0, 'Hello World');
$name = '/test.pdf';
$headers = array(
'Content-Type: application/pdf',
);
$filename = storage_path() . $name;
PDF::Output($filename);
return $filename;
And in the callback of the AJAX request I display a confirmation Alert.
However analyzing the element inspect, in the network tab, I get the following answer
%PDF-1.7
%����
7 0 obj
<< /Type /Page /Parent 1 0 R /LastModified (D:20141016181750-03'00') /Resources 2 0 R /MediaBox [0.000000 0.000000 595.276000 841.890000] /CropBox [0.000000 0.000000 595.276000 841.890000] /BleedBox [0.000000 0.000000 595.276000 841.890000] /TrimBox [0.000000 0.000000 595.276000 841.890000] /ArtBox [0.000000 0.000000 595.276000 841.890000] /Contents 8 0 R /Rotate 0 /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Annots [ 6 0 R ] /PZ 1 >>
endobj
8 0 obj
<</Filter /FlateDecode /Length 295>> stream
x���Qo�0���+Σ��ۖ���9]|r[�-Q_&H�`�d ٿ_%AQ�1p�
�m���ˁ�6�s�_X��+�9����`* �Sp[<9Fw��p?�#]vM���[FG�j�a�c��1)؋z�%���E�u�U�2
&4�L��,G�i�x/�<�������:Z��R�-�/�*-���p����QUU�g��lyQf��j��|7�����
�CI�I����z�C nt��u��*�Bm��V�k�ȚV9��л���~��_�*�҈����8�D�p;�� ���|�o
endstream
endobj
I have tried to put the headers and I can not display or force the PDF download, but testing without AJAX in a request to a route with only the code to generate the PDF, it generates and displays in the browser normally.
I would like after the insert in the bank to be generated a PDF and open in a new tab, with the information for printing.
Or another solution to generate PDF or print.
Have you tried in the sucess callback to get a different route that only download the pdf ?
– gmsantos
So I thought about it, but for example, the file is in the Storage folder, as I would a route to it ?
– Juliano Rossi
It would look something like this, replacing the path of $file - http://stackoverflow.com/a/20415796/2099835
– gmsantos