-1

First of all I know how to change the color of SVG dynamically. I have used the solution from this question:

jQuery SVG image replacement

But my scenario is different.

On my page I have several icons (SVGs) and there is a color picker. The user can change the of icons using colorpicker. All works fine.

Now I want to generate the PDF of the whole page with the color of icons selected by the user.

I am using third party PDF generation library that takes my page URL and generates the PDF of that. But the problem is that the color does not get applied to the icons and PDF is generated. I know the cause of this problem because as on document ready I convert all the SVG img tags to actual SVG tags and then apply the color to them chosen by the user. This all happens after the page has rendered.

But the PDF generation library does not wait for this process to complete and generates the PDF before all the SVGs images are converted to SVGs and color is applied to them.

I don't know to first wait for whole process to complete and then generate its PDF.

I have tried caching of the page but that does not help either.

Any help would be highly appreciated. Thanks

Community
  • 1
  • 1
Hammad
  • 2,097
  • 3
  • 26
  • 45
  • 1
    We really need a [mcve] so we can see what you're doing. – Robert Longson Mar 06 '16 at 07:41
  • Due to privacy I am unable show the page. But let me explain clearly. I have a interactive page and there are 10 icons on that render as . There is a colorpicker on the page as well with which the user can change the color of icons. The selector color is saved in database. So next time when the page loads the icons should be colored with the chosen color....continued... – Hammad Mar 06 '16 at 07:49
  • I used the solution (link given in question) to first convert all the having .svg as its source and convert them to tags and then I applied the color to each of them using jquery. But this process is possible when the page has rendered. After completion the user would generate the PDF of that page. But since the color process occurs after page has rendered the PDF generation library generates the PDF before this process occurs so the icons are not colored in generated PDF – Hammad Mar 06 '16 at 07:52
  • We don't want the page we want a cut down testcase that runs. – Robert Longson Mar 06 '16 at 07:53

1 Answers1

0

I did that.

The solution was to wrap the code in IIFE so that it executes immediately on page load rather than on ready event of the DOM.

Hammad
  • 2,097
  • 3
  • 26
  • 45