Currently, i am using the following code :-
(I have marked the two important lines in the code. Between these lines are just some operations on existing documents)