Export PDF with images?

Export PDF with images?

yetyet Posts: 43Questions: 17Answers: 1

We have a DT column containing images and logos (using <img> tag).

Is it possible to include these images and logos as part of the PDF export? Or even as part of the "print" export?

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    This example shows how you can do images in the pdf. It is not trivial I'm afraid, the pdfmake library that is used to provide the pdf export doesn't make it particularly easy. If you are using images in the table it is even harder since you need to provide each as a base64 encoded image to the pdf generator.

    For print, use the stripHtml option of the print button export options. By default it is set to strip the HTML tags, so img elements would be removed.

    Allan

  • Venky1995Venky1995 Posts: 14Questions: 9Answers: 0

    @allan In the same situation, how would you display the image at the end of the PDF? How would the doc.content.splice change ? Thanks for such a great library!

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974
    edited January 2020

    @Venky1995 I'm not sure its exactly the same as the OP is asking about images in each row.

    display the image at the end of the PDF? How would the doc.content.splice change ?

    Let's take a look. Here is an example:
    http://live.datatables.net/jatobaqi/1/edit

    It has 3 PDF buttons; one with no changes, one using this example and one placing the image at the bottom of the document. It is also using console.log(doc.content) for each button so you can see the differences. Looks like doc.content is an array of objects. The 2nd and 3rd buttons manipulate the array to place the image where desired.

    Kevin

This discussion has been closed.