How to use Convert to pdf in a for command in windows?

Hello,

I have just tried to use convert to pdf in a for but when it works it does not save the pdf generated in the appropriate subfolder, it saves it in the current path where the batch file is saved. Here I post my script:

FOR /R "C:\Users\ear\Documents\rd" %%G 
IN (*.odt) 
DO "C:\Program Files (x86)\LibreOffice 4\program\soffice.exe" --headless --invisible --convert-to pdf "%%G"

And when I use outdir I cannot put %%G, then it does not work, but if I write, for example, “C:\users\ear\documents”, a specific folder, then it works. But I don´t want to save it a specif folder all pdfs, I want to save each pdf in his appropiate subfolder where its source file is.

How can I solve this problem?

Thank you!!