jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

Use image as page background

Open betsonserviceportal opened this issue 8 years ago • 5 comments

Is it possible to use an image as the background for a page and then overlay the autoTable? I can overlay images using just jsPDF, but can't figure it out with AutoTable. What I've tried so far is to addImage the full page size in the pageContent. The image lays overtop of the table so I can't see the tables.

betsonserviceportal avatar Mar 26 '18 19:03 betsonserviceportal

I kind of figured this out, so you can delete if you want. I was able to subscribe to the addPage event. Not sure how to unsubscribe! In case this helps.

doc.internal.events.subscribe('addPage', function() { pageSize = view.doc.internal.pageSize; doc.addImage(myimage, 'JPG', 0, 0, pageSize.width, pageSize.height); });

betsonserviceportal avatar Mar 29 '18 00:03 betsonserviceportal

Innovative solution! And as soon as the document is finished rendered you automatically unsubscribe in jspdf so you don't need to worry about that 👍

simonbengtsson avatar Aug 04 '18 12:08 simonbengtsson

What if you want the solution to work also in the first page? This workaround applies after the doc.addPage is in the code and I was looking to also apply to the initial page. Thanks!

soleuil avatar Feb 07 '22 11:02 soleuil

What if you want the solution to work also in the first page? This workaround applies after the doc.addPage is in the code and I was looking to also apply to the initial page. Thanks!

I solved this by removing and re-adding the first page after the subscribe:

doc.deletePage(1)
doc.addPage()

Probably a bit hacky but at least it works.

Seemeile avatar Sep 05 '23 12:09 Seemeile

I kind of figured this out, so you can delete if you want. I was able to subscribe to the addPage event. Not sure how to unsubscribe! In case this helps.

doc.internal.events.subscribe('addPage', function() { pageSize = view.doc.internal.pageSize; doc.addImage(myimage, 'JPG', 0, 0, pageSize.width, pageSize.height); });

Thank you

muthu920 avatar Jun 27 '24 15:06 muthu920