Render Javascript Function? Base64 Images?

Render Javascript Function? Base64 Images?

somma_mattsomma_matt Posts: 20Questions: 5Answers: 0
edited September 2016 in Free community support

I'm pretty new to all of this so this might not be a datatables question.

I have a folder of images "images/" containing about 1200 images.

I have created a row called "image" in my datatable to render an <img> tag based on the cell contents. I do it under column render.

I want the PDF (using pdfmake) to include these images, but need to convert them to Base64 strings for this to work.

I've found plenty of different scripts that convert images based on a URL to a Base64 string.

Any idea how to have it loop through a javascript function that encodes it to Base64, return the string in 1 column, then write the image code into a separate column?

www.mattsomma.com/ilt/blanks2.html

Thanks in advance :)

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I think the problem you might run into here is the async behaviour of loading remote images. The customize callback for the pdfHtml5 button is synchronous, so you would need to load all 1200 images synchronously. While that makes the for loop trivial, it is going to kill performance. It will probably take minutes for the action to complete.

    For a PDF with that many images I'd encourage you to consider using a server-side script to create the PDF and a simple button that will then load that PDF. It might not be required, but it is something to have a think about!

    Allan

  • somma_mattsomma_matt Posts: 20Questions: 5Answers: 0

    Most times all 1200 won't be exported (it would be like 20-30). Would that make it easier?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I don't think it would effect the ease of implementation at all, but it would certainly make the pdf generation a bit faster. As I say, the async / sync issue is going to be the biggest issue you face when implementing that.

    Allan

This discussion has been closed.