0

I'm curious as to whether there is a method for what I want to do. For instance: Let's say I have an SVG and decide to animate it, and every time it's run, the stroke-offset I have set is randomized, and infinite.

An example of the stroke animation is this, minus the randomization: https://css-tricks.com/wp-content/uploads/2014/02/animate-stroke.gif

Now. If I want to open that SVG and print it (Pressing Ctrl/Cmd + P) straight from the desktop (not within any other application)— is it possible for the SVG to run it's randomization when I print it?

Again, I understand some may comment—"Print is dead, what are you doing..." But this is out of curiosity.

Print isn't dead. It just sat back and watched as we fiddled with our new toys.

John Connor
  • 175
  • 1
  • 2
  • 7
  • 1
    "the day print is dead is the same day the IRS accepts you holding up your phone and saying ... here is my receipt" – Kevin Brown Jul 19 '17 at 23:17
  • Please explain what you mean "run it's randomization" when i print it. Do you mean you want to create some document that is the exact appearance of the time selected to print? Or do you mean you want some digital document (like PDF) with animation in it? – Kevin Brown Jul 19 '17 at 23:24
  • @KevinBrown When I print the SVG it would generate a design before printing, but you would not see the preview of the actual document that prints—the printer would re-interpret the printed file and generate a different image, similar to generative design, where every time it is generated, it is different. In this case, every time it is printed, it is regenerated... I feel I am asking the impossible, and I believe I am. But I'm curious to hear the thoughts of others. – John Connor Jul 20 '17 at 00:05
  • Go to this page I did ... http://www.cloudformatter.com/GoogleCharts. You will see many of the charts have animations set to change. At the exact moment in time you select to "print" in the many various ways, it will be the exact SVG at that time. Is that what you are asking? – Kevin Brown Jul 20 '17 at 00:26
  • @KevinBrown Close but no cigar—In the event that I or anyone would press print, you would see what you _think_ is going to print, but when it prints, the results are different from what you saw on the screen. As the file is rendered for printing, it would change, but you would never see the rendered version until you print it. – John Connor Jul 20 '17 at 14:14

1 Answers1

1

Using Javascript, you can detect when printing is happening by adding a listener to the beforeprint event. See: Detecting browser print event

Then stop the animation (by adding a class, for example), and set your stroke-dashoffset to whatever you want.

Then reset everything back afterwards by listening for the afterprint event.

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181