You could use JSPdf library for this case. You have to took at JavaScript plugin and at addImage plugin source codes of this library to see how a file attachment could be done. I think that the JavaScript plugin source code is more understandable for this case.
I am not looking for a complete solution
Yes, a complete solution you have to write by yourself because now this library does not support a custom file attachment.
Files are attached using binary file streams, that looks like this in the PDF file:
32 0 obj
<</Type /EmbeddedFile /Subtype /{mimetype} /Length 72>>
stream
{file data}
endstream
endobj
Yes, some like this you have to write. You have to realize that you have to write a code for reading from a PDF file too.
Alternative solution
But, if it is too difficult or too much work for you then you have to think about doing of all this on the server side. You could send to your server a request using AJAX and the server do it and gives you a new PDF back.
In this case you could edit a PDF server side with free PHP library like FPDI for example. With FPDI it is possible to read and to edit PDF documents (use createByFile()
method to read a PDF). The FPDI is extended version of FPDF library, which has the plugin for attachments.