It's correct to use a preposition followed by an infinitive, yes. In fact, you must use an infinitive after any preposition (not a gerund). In this case, though, meaning "by doing something" we don't use any preposition with the gerund as we say in the lesson, and using: por + infinitive here wouldn't work if what you want to say is "by doing something [you achieve something]".
However, if the meaning was slightly different, expressing a "cause", i.e. "He lost weight because he drank two litres of water a day.", you can say:
Here is a lesson on this use of por.
I hope it clarified it.
It is a subtle but significant difference between the two possibilities. Thank you for explaining inma.
Sign in to submit your answer
Don't have an account yet? Join today
Test your Spanish to the CEFR standard