This is the story of Hungarian folk hero Lúdas Matyi.
There are several (live-action) adaptations of this popular poem/tale, but in 1977 renowned Hungarian animation director Attila Dargay made an animated version of the story, you probably saw this version:
"Lúdas Matyi", a.k.a "Matt the Gooseboy" (1977)
You can watch the complete animated movie in its original Hungarian here:
He has a goose companion.
Here is a screenshot where he tricks the king guy into measuring a tree and beats him with his umbrella:
I am sure this is the story/version you are looking for. If you agree, please select my answer as Best Answer by clicking on the yellow star next to it.