Call to a member function set_signature_certificate() on bool - php

could you help me with this problem?
I am trying to create and download a signed PDF.
Once the generated PDF file exists, I can't sign in because of this error.
"Call to a member function set_signature_certificate() on bool"
in browser and
"Error info at /Users/martinkravec/git/projectname/vendor/ddn/sapp/src/PDFUtilFnc.php:377: PDF version string not found"
in stderr.log.
I am running the following code outside CLI in Laravel 9 with PHP 8.1.9.
config/app.php
in provider:
Barryvdh\DomPDF\ServiceProvider::class,
In aliases:
'PDF' => Barryvdh\DomPDF\Facade::class,
Controller
use PDF;
use ddn\sapp\PDFDoc;
if (!defined('STDERR')) define('STDERR', fopen(__DIR__ . '/../../../storage/logs/stderr.log', 'wb'));
require_once(__DIR__ . '/../../../vendor/autoload.php');
class ClientController extends Controller
{
public function index()
{
$pdf = PDF::loadView('pdf'); // temlate in resources/views/pdf.blade.php
$fileContent = $pdf->stream();
$obj = PDFDoc::from_string($fileContent);
$certificatePath = __DIR__ . '/../../../storage/app/test_certificate.pfx';
$password = '';
$obj->set_signature_certificate($certificatePath, $password);
$signedPdf = $obj->to_pdf_file_s();
return response()->streamDownload(function () use ($signedPdf) {
echo $signedPdf;
}, 'export.pdf');
}
}
When I do
cat ./file.pdf
I get file content starting with:
HTTP/1.0 200 OK
Cache-Control: no-cache, private
Content-Disposition: inline; filename="document.pdf"
Content-Type: application/pdf
Date: Sun, 28 Aug 2022 09:37:03 GMT
%PDF-1.7
1 0 obj
<< /Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R >>
endobj
2 0 obj
<< /Type /Outlines /Count 0 >>
endobj
3 0 obj
<< /Type /Pages
/Kids [6 0 R
19 0 R
]
/Count 2
/Resources <<
/ProcSet 4 0 R
/Font <<
/F1 8 0 R
/F2 13 0 R
>>
/XObject <<
/I1 18 0 R
>>
>>
/MediaBox [0.000 0.000 595.280 841.890]
>>
endobj
4 0 obj
[/PDF /Text /ImageC ]
endobj
5 0 obj
<<
/Producer (���d�o�m�p�d�f� �2�.�0�.�0� �+� �C�P�D�F)
/CreationDate (D:20220828113702+02'00')
/ModDate (D:20220828113702+02'00')
/Title (���D���v�k�y�.�P�D�F)
>>
endobj
6 0 obj
<< /Type /Page
/MediaBox [0.000 0.000 595.280 841.890]
/Parent 3 0 R
/Contents 7 0 R
>>
endobj
7 0 obj
<< /Filter /FlateDecode
/Length 919 >>
stream

I have found the problem.
Instead of reading the PDF file content using
$pdf->stream()
we need to save the file using
$pdf->save($fileName);
which does not generate the first 6 lines of a file and probably some more things causing an error with the version.
Thanks for helping #Peppermintology anyway.

Related

What makes Adobe Reader display the "Signed" panel?

I am signing PDF files server side with PHP and I want Adobe Reader to display this banner on my resulting PDF saying that the file has been successfuly signed :
I am using code from the TCPDF library to achieve this (I had to modify some code to fit my needs).
I based my work on these two documents from Adobe official documentation : doc1 and doc2.
What I do :
Add the signature tags to the PDF file :
// The ID of the last object of the PDF + 1
$sigobjid = preg_match_all("/([0-9]+) 0 obj/", $pdfdoc, $output_array);
$sigobjid = end($output_array[1]) + 1;
// Write the signature tags where needed
$index_to_write = strrpos($pdfdoc,"endobj") + 6;
$signature_tag = PHP_EOL . $sigobjid . ' 0 obj '. PHP_EOL . '<< /Type /Sig /Filter /Adobe.PPKLite /SubFilter /adbe.pkcs7.detached '. TCPDF_STATIC::$byterange_string . ' /Contents<'.str_repeat('0', $tcpdf->get_signature_max_length()).'> >>' . PHP_EOL . 'endobj';
$pdfdoc = substr_replace($pdfdoc, $signature_tag, $index_to_write, 0);
Compute and replace the ByteRange
Compute the hash of the file like this :
$hash_result = hash('sha256', $pdfdoc);
Sign the resulting hash client side with forge.js : I use a PFX file that I parse and then create a PKCS7 using the data contained in the PFX.
Send the hash to server.
Add the signature to the PDF in the Content tag.
EDIT : Thanks to #mkl comment I also tried to reference my Sig object with the AcroForm with the following lines into my PDF file :
11 0 obj
<< /Type /Sig /Filter /Adobe.PPKLite /SubFilter /adbe.pkcs7.detached /ByteRange[0 2846 14590 507] /Contents< ...
endobj
12 0 obj
<</AcroForm 11 0 R >>
endobj
It is not working either. How should I fill the AcroForm field ?
The resulting PDF is readable by Adobe Reader but the blue banner does not appear, why ?
Okay I solved it myself so for these who were wondering, you need those fields :
1 0 obj
<<
/Type /Catalog /AcroForm << /Fields [12 0 R 13 0 R] /NeedAppearances false /SigFlags 3 /DR << /Font << /F1 14 0 R >> >> /DA (/F1 0 Tf 0 g) /Q 0 >> /Perms << /DocMDP 11 0 R >>
>>
endobj
4 0 obj
<<
/Type /Page
...
endobj
11 0 obj
<< /Type /Sig /Filter /Adobe.PPKLite /SubFilter /adbe.pkcs7.detached /ByteRange[0 3153 14897 922] /Contents<...> /Reference [ << /Type /SigRef /DigestMethod /SHA256 /TransformMethod /DocMDP /TransformParams << /Type /TransformParams /P 2 /V /1.2 >> >> ] >>
endobj
12 0 obj
<< /Type /Annot /Subtype /Widget /Rect [510.236220 572.598661 552.755906 615.118346] /P 4 0 R /F 4 /FT /Sig /T (Signer Name) /Ff 0 >>
endobj
13 0 obj
<< /Type /Annot /Subtype /Widget /Rect [510.236220 572.598661 552.755906 615.118346] /P 4 0 R /F 4 /FT /Sig /T (Signer Name) /Ff 0 /V 11 0 R >>
endobj
14 0 obj
<</Type /Font /Subtype /Type1 /BaseFont /Helvetica /Name /F1 /Encoding /WinAnsiEncoding >>
endobj
You basically need :
1 Font object (obj 14 in this example)
1 Sig object (obj 11) containing the signature in the 'contents' field
1 Page object (obj 4)
2 Annot object (obj 12 and 13) referencing the first page object with the P flag and the Sig object with the V flag
1 AcroForm field inside your main Catalog (obj 1) referencing your 2 Annot object in the Fields array, referencing your font in the F1 field, and your signature in the DocMDP field.
EDIT : The DocMDP field is not mendatory and only one Annot is needed. No Font required either.

Why html2PDF generated script only NOT functioning with Google Chrome (54v)? But same script properly working with Mozilla Firefox (50v)

I used html2PDF module to convert and HTML code written in PHP to convert in to PDF..
The same script is properly working in Mozilla Firefox Browser in version 50.. (Latest)
But when I tried the same page using Google Chrome browser in version 54. (Latest) it is generating following outout instead of PDF...
As per this, there should not be any issue with the code.. Because it's working with firefox..
What can be the issue for this?
This is the wrong output I got when tried with Google Chrome;
%PDF-1.7 3 0 obj <> /Resources 2 0 R /Contents 4 0 R>> endobj 4 0 obj <> stream x��]]�5�}���G�%�>yk�`��nv�σ�z��kCcbf#�ǯ�Z���Tc��0m�3�O�<����R))��i�����O���w�׿��|S��q�a�gw>:��폡C�����~g������\}�3����~��1��.L����[�]we��^>����.�_��?�߄8���MS��Н�����O?����٣���_>�������[w�'!���Z��Rߤ�5��C���_tsz����GgκG_��#�w�~��G��rv��7����z����o˕�?�|���ׯ>�BHaX�y|�[�4��2Ϡ�5���{��}�/��}�����G�V�]�y��a�S�����z~��U������ۢz��u$��V�k��HR?���{xv�������i�e��tO���y�(�����_�ʭ����q��+߿��g���B����B���}u���������~������������8���>�k�C���)����_� 66et3^k��>���_^>���o����+㥩� lr�//�Ïpʀ*l�)m�?�3� �!�7���萔���~g��x��`.O�tCm�د�M�Y�0�П%��M��2�K�a;2�n��:�)ݔ���|Cm[�����������' �����I�ܯ�M9[?�jc���}o�tI� ߹�~�n�-& m����_ι��&^ۑH<�A��׵i��.ǥD�����d=���̟r�}�o�3���ۼ���u��,��8�6t�nJ8�g��֏�������_���JڂL�}d:ql���a��������zF n� n}��WW���?�(>\�(������Z֛�^�ߐq�z�S��tw��'��c(wb,��t���on�pKr�w����G�>�M��f�S�����?�?��~��~���ǷuZ&ĵF�����ǷV�4�crzC��������ԯ�S���{�Uo����z��-C�����[,�zi�;�W�>>���/��>�����W��|x[o��� ��xmI�[�ڒ����E�O����1�N_�2*������vo��-�nA�[�ޒ��6����-xoQ������72ɘ�Q��m���|�Q&z��Wȓ��u�I��j�M2����&3�`�O��*�T!r�+g��N2��v�m�:9tn̮V����>��c�����a�{�_1�{^����p���{��O-��l+��l���co>�rGN-K���f�4W{��=�P���>$�M��jﱷfY/�>$�T�i��{{�a���>L���*6���co>�k���(�#��b�\�=����ԯ}���4Ul�����|HR�>�~�oI�i��{{�a�N|�s8�T�i��{{�a_B��Sl�����|�$�6Y�M��jﱷYC?��m�gx� ��jﱷ?��~��'������coo-�m�z𡤃j�X���{������}H{gy�T�i��{{�a���>�t;0Ŧ��{����=��~ƧU�i��{{�a�Z�a�e�T�i��{{�a��|�� �*6���co>�RW>����b�\�=����"?�K�a�Tl�����|�2�B?�T�i��{{�a�*�a�'���Ms���ۃC��aϑASŦ��{��O>�A�N>�#I�aլ�{���&�c'֕�BêY�=���C��U|����R�i�3?7|�a�L8�s�`�Tl�ʌ������� |eA4Ul�����|�d��0�c�b�\�=����$�&�a�\Z�i��{{�a_[�҆Ms���ۃ��`��ꤩb�\�=���Cy�p��)�M��jﱷV��Ň��+������ ����X�M��b�h<�����c�T[�\Z�jV{���ɇe���'��riêY�=���C�jA�!�<h��4W{��=���5Q'�~�X��4W{��=�� �FY�M���� ���/>̐��S?b�Tl�gO0?7���抱u�8�Vl�����|��|H�K+6���co>�Ls��d�+��jﱷJ6���R�u���Ms���ۃ+����+������ _|���eԄ�R�i<� ~n���J}��: �K+6���co�a.�S��S.�X5������ôo��䁦�U��{�������{�K?b�Tl�����|������JŦ9�x�����3����$�#SŦy���s��~��:M�K+6���co>�����`ʥ��jﱷf�f)�M��jﱷ�)��s�E�T�i��{{�a�|���Aæy���s�����#^6́��� _|��[�W�'M�M�F��s�?�m����X��4t����ao�V�u�o�aլ�{��rg0��;��R�jV{��=�!�E.æ9�x�����3���c�5l�gO?7�þs �w,��riŦy������Ň�z Y �\Z�i��b~n���M�E�Dc���M�D�(�s�e��(��6͉2���/>,����a�Q6��'���aos������6͑��� _|�(�L��bӼQV����Ň�2�P2,ʥ���2c���_|�,so�1V*V�jﱷ?� �,�ޒ����J�,���ۃ��q�5�wΰi�<� ~n���O��0��g�4/<� ~n���M��2j�\Z�iN4�e~n���D#� #?���M�D#v���/>L4� ;1q�ði�(2?7���&Μ�c�Tl�G���� _|X��8�{æy���s�"�z�C�^Ѱi�<� ~n���J�pQfs0V*6�+��1?7|�a��Đ6Υ���f��~�Af�0��Y5���U��{��O>�6qF7��f� �f���ۃ2����3]æ9�x�����d���LٺaӼ�x������Vb��riŦ9���s�&Z�L��b�lTm���*��捫툟~�A*�0�U-V�jﱷ�� �"���W4{��=��B�/>,�l�4�<� ~n���M�>�SU0�6l�#U�2?7|�a� �&Υ���*h����0Rp:U�WMU.����|��9�*ԫ��j���co>̐�w��M�L� ���/>$��ŇHU*�Ms���s���Vʥ ���꿙����>[|8�Vl��3?7��~�O��5�}6l�7��b~n���M� ���M����~�!���;��3êY�=��'��`� wc�bլ�{{�!B}����G1l�#�3?7|�a���㎱W4l�g��f~n�����Ї�j� ���*9����0�)�0r��b�\�=������0SE�a�lԂ`�Ұiި���/>�-I�<�(��x����ٳ�Qe3VI1P*V�jﱷ��f����ˢ�^N�tƠ>ҋ&���Mm������Ŋm���*w�#A�칇�5uI�~GŦ6Q�c~n�E�D�Zz`�P�N���=W�O��$)�ǰ���N��0?7��4�����^)T�#u��͞+���c�a��.��3?7��>RƲJ���H� q������$�5 �ڕ.���_��3��� U�# #q���2�AS��0*V�jﱷ��b��Ãw ����Ag� :�LXbTlj :��~Q�иI ��IS�r47{��O4�Ki���aS�h��������F�2� o�B�;Ѱ���sE�D��f�6� ���~Q?��A!���B�;��q����p�#I�;F#Ŧv�����_�G�����7 Un���f��+M>%)y���Ԯ< ~n�i��ց����#��f�-���#�8p�Xժ����ZX6��\VJ�˩������M�x�P�� 4�������搥���܅&���=W�'�O�H���Mm�ğ����3��Ky;��*w�����s{k����#�bS;�"�s�/�GZG��vx/�ܑQ��=W�ϴ�ƅ���ڙ�����A�ĕ,)���P�&Z�"n�\Q�B>~�1.6���coRh-Qʐ�^�� ��7{���h)4I!;F#Ŧv��P����3o��+�`p��˩�����~ ���H��U��{��O�WZO�Z�W�rWZL'n�����$)%����F����~Q?SE��~�1PN�P�FJ���=Wԯ�]0Iq9F#Ŧv��������~��QJ������Qc��I���c���V�jﱷ?����]y,��Pm�;���]ݖYi K9��æ6p�O�������5sT�]Ppo�T��b�����x��D��� _rp�w-���'��`L<�1�h�։�q�"r�n�ډ"2�s×Y�P��$7=�f��3In㾴�]a��qz.����coj!rg8 ��D��#w��e!I ����8�UljW�xd~n�RN#�?�����������'U�&)��6д�a�e��� _�G�����Y���������"��b���X�Ulj���� _�;� (���.o�\x���F>I֟1b��4>��Mm�����/�H�����Nn�+#3��3�uJk8�L��E��M�H#O���/G��)#�2J�#w���!Fi�iȟ���{�ڙ�}���/�I�9L�����$)��x�xt�-I��1bJQ8F#Ŧv��f���/G��IXo�x�}p���)X���JR�7)�7ð�ݸ���������p��ޕ�}7.i޸�yuG��R>��H3��-���3?7|9$��.\ʻp���W�7��^i ���oŦ6RQ�s×�.�<>)�⺉��\���=���G=~r����>��Cp#������uE��:T�?����ʍ|��Uwy���//�y�;��Y������?�����]���|���������o��A,IJ� �q��w�i�� ��-���}��_ endstream endobj 1 0 obj <> endobj 5 0 obj << /Type /OCG /Name (��print) /Usage << /Print <> /View <> >> >> endobj 6 0 obj << /Type /OCG /Name (��view) /Usage << /Print <> /View <> >> >> endobj 7 0 obj <> endobj 8 0 obj <> endobj 9 0 obj <> endobj 10 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 7 0 R /F2 8 0 R /F3 9 0 R /F4 10 0 R >> /XObject << >> /Properties <> /ExtGState << >> >> endobj 11 0 obj << /Creator (��HTML2PDF - TCPDF) /Producer (��TCPDF 5.0.002 \(http://www.tcpdf.org\) \(TCPDF\)) /CreationDate (D:20161128153553+05'30') /ModDate (D:20161128153553+05'30') >> endobj 12 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /Fit] /PageLayout /SinglePage /PageMode /UseNone /Names << >> /ViewerPreferences << /Direction /L2R >> /OCProperties <> <>]>>>> >> endobj xref 0 13 0000000000 65535 f 0000006302 00000 n 0000007029 00000 n 0000000009 00000 n 0000000175 00000 n 0000006362 00000 n 0000006481 00000 n 0000006598 00000 n 0000006704 00000 n 0000006812 00000 n 0000006919 00000 n 0000007219 00000 n 0000007469 00000 n trailer << /Size 13 /Root 12 0 R /Info 11 0 R >> startxref 7829 %%EOF
charset is not supporting and enable force download:
set header content to force download:
$response->headers->set('Content-Type', 'application/force-download');
set charset:
for HTML4: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
for HTML5: <meta charset="utf-8">

Laravel 5 DOMPDF - Stream Only

I want just to stream pdf file in the browser. I have folder invoice inside public folder. Inside invoice folder I have my file. I want to stream that file in browser via dompdf laravel package.
Does anyone have an idea how to do it?
I have tried something like
return \PDF::loadFile(public_path().'/invoice/'.$invoice_name)->stream($invoice_name);
but it doesn't work.
Here is the response:
%PDF-1.3 1 0 obj > endobj 2 0 obj > endobj 3 0 obj > >> /MediaBox
[0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5
0 obj > endobj 6 0 obj > endobj 7 0 obj > stream xWMs0WPoY=B?
MM?N.~=?Vr$;}?_#J(>9I(tFl78Va~W_G8fI&01M:s.N.]?ygy{t7yUE,M},jx Or"$
fG ?1DQ%BCWlJJ] ?A[?3feh|"3bmyEB&R5?E?EDhuWtM+*iVy[e(+[\b m?``iIenq2m
|nV?;%?N1q?lw*4c
+..jX$??VL3>pjxs`4)d*uER9(N~_{6
I really have no idea what to do. :)
$invoice_name is name of pdf file i.g "invoice-22.pdf"

Error with DomPdf render html in php

I try to render view HTML, with div, tables, thead, tboody, tfoot, h2, h3 and ccs.
The result of my render in php with donpdf is:
"%PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R >> >> /MediaBox [0.000 0.000 612.000 792.000] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Creator (DOMPDF) /CreationDate (D:20130227215320+00'00') /ModDate (D:20130227215320+00'00') >> endobj 6 0 obj << /Type /Page /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 66 >> stream x��2�300P#&�ҹ�B�M��́����BH����������BH��B���H�f�B���k�� endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Times-Roman /Encoding /WinAnsiEncoding >> endobj xref 0 9 0000000000 65535 f 0000000008 00000 n 0000000073 00000 n 0000000119 00000 n 0000000273 00000 n 0000000302 00000 n 0000000416 00000 n 0000000479 00000 n 0000000616 00000 n trailer << /Size 9 /Root 1 0 R /Info 5 0 R >> startxref 725 %%EOF"
Any idea why dompdf renders this response?
This is the code generate Pdf:
class PdfView extends PhpView {
public $orientation = "portrait";
public $size = "letter";
function render(Response $response) {
$response->resetBuffer();
parent::render($response);
$buffer = utf8_decode($response->getBuffer());
$response->resetBuffer();
Context::load("app/core/lib/dompdf/dompdf_config.inc");
$pdf = new DOMPDF();
$pdf->set_paper($this->size,$this->orientation);
$pdf->load_html($buffer);
$pdf->render();
$render = $pdf->output();
if ($path = #$response->result->options->save)
file_put_contents($path, $render);
else {
$response->setHeader("Content-Type", "application/pdf");
echo $render;
}
}
}
The header of app is "application/pdf".
Plz help me!!
I had the same problem. The basic issue can be found it in the class library, at the lines:
/* FUNCION QUE DARÁ ERRORES*/
/* Function with troubles*/
if (PHP_VERSION < 6) {
$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
}
$file_buffer = file_get_contents($path);
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
return $file_buffer;
}
You must replace with this code :
/* NUEVA FUNCION CORRECTA */
/* Fuction correct*/
if (PHP_VERSION < 6) {
$magic_quotes = get_magic_quotes_runtime();
ini_set("magic_quotes_runtime", 0);
}
$file_buffer = file_get_contents($path);
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
if (PHP_VERSION < 6) { ini_set("magic_quotes_runtime", $magic_quotes); }
return $file_buffer;
}
I hope this code help you :)

Open Fpdf JSON response, in new window, to save PDF. - PHP

I'm trying to send a Json array over using an AJAX call to a controller function which processes the data using a FPDF library which is already implemented into Codeigniter. I can see the PDF data being returned, but how would I go about opening this PDF data in a new window so the PDF can be saved. It doesn't matter if the PDF cant be viewed i just need to save the generated file.
Here's the code I have so far:
Jquery Code
<script defer="defer" type="text/javascript">
$(document).ready(function() {
$('a#export').click(function(exportRecord) {
var postData = {
'record_type' : 1,
'title' : 'Some Title Here',
'content' : 'Some content here',
};
$.ajax({
url: "<?php echo base_url().'admin/pdf/createPDF';?>",
type:'POST',
data: postData,
dataType: 'json',
success: function(data){
window.open(
'data:application/pdf,'+encodeURIComponent(data),
'Batch Print',
'width=600,height=600,location=_newtab'
);
} // End of success function of ajax form
}); // End of ajax call
return false;
});
});
</script>
The Controller Function
<?php
function createPDF(){
$content = $this->input->post('content');
$font_directory = './assets/fpdf_fonts/';
set_realpath($font_directory);
define('FPDF_FONTPATH',$font_directory);
$data = $this->fpdf->Open();
$data = $this->fpdf->AddPage();
$data = $this->fpdf->SetFont('Arial','',8);
$data = $this->fpdf->Cell(80);
$data = $this->fpdf->Cell(0,0,$content,0,1,'R');
$data = $this->fpdf->Output();
}
The JSON Response
%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 72>>
stream
x�3R��2�35W(�r
Q�w3T��30PISp
��陛)X��(��(hx����+���i*�d�����F
endstream
endobj
1 0 obj
<</Type /Pages
/Kids [3 0 R ]
/Count 1
/MediaBox [0 0 595.28 841.89]
>>
endobj
5 0 obj
<</Type /Font
/BaseFont /Helvetica
/Subtype /Type1
/Encoding /WinAnsiEncoding
>>
endobj
2 0 obj
<<
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/Font <<
/F1 5 0 R
>>
/XObject <<
>>
>>
endobj
6 0 obj
<<
/Producer (FPDF 1.7)
/CreationDate (D:20120309201958)
>>
endobj
7 0 obj
<<
/Type /Catalog
/Pages 1 0 R
>>
endobj
xref
0 8
0000000000 65535 f
0000000228 00000 n
0000000411 00000 n
0000000009 00000 n
0000000087 00000 n
0000000315 00000 n
0000000515 00000 n
0000000590 00000 n
trailer
<<
/Size 8
/Root 7 0 R
/Info 6 0 R
>>
startxref
639
%%EOF
""
Maybe a bit late, there is my answer I got the system working.
For a reason that I don't understand it doesn't work with ajax call.
This post helped has done the magic :
JavaScript post request like a form submit
HTML (here the call the PDF generator in PHP with POST parameter ):
post('GenerateStockLabelsWPDF.php', { CSVTable: JSON.stringify(encodeURIComponent(CSVtable))});
Then PHP (For the sample it's a fixed text, you can adapt it by getting variable via _post):
<?php
include "php/fpdf/fpdf.php";
$pdf = new FPDF();
$pdf->Open();
$pdf->SetMargins(0, 0);
$pdf->SetAutoPageBreak(false);
$pdf->AddPage();
$content = 'thisis a test';
$pdf->SetXY(20, 20);
$pdf->SetFont('Helvetica', 'B', 10);
$pdf->MultiCell(150, 5, $content, 0, 'L');
$pdf->Output('Labels.pdf', 'D');
exit;
?>
Save the generated file where? On the users computer? On the server?
Looks like $data in the createPFD method is the PDF.
For the former, check http://codeigniter.com/user_guide/helpers/download_helper.html
force_download('coolPDF.pdf', $data);
For the latter, check http://codeigniter.com/user_guide/helpers/file_helper.html
write_file('/path/to/these/PDFs/fileName.pdf', $data);

Categories