Bugfix in dyn_saveas

Fixed a bug for the non-Octave version where only the last active figure
was printed instead of the figure with the actual handle. Octave
eps-version still needs to be taken care of.
(cherry picked from commit cd26c3cebd82140c8354cd6596d19d9459171fad)
Fix dyn_saveas for Octave
(cherry picked from commit c58aebd2ef1af574ad14e6186375b8c729ed0e7f)