Are you trying to change the size on the fly for different values for instance.
Or is this simply ensureing the page is formatted correctly when the document is opened?
I could not get your code to work
but this code appears to work OK
xfa.form.form1.pageSet.pageArea.medium.stock = "A4";
Hope this helps
Unfortunately, I dont believe you can change the medium at runtime through script. Unless it has been changed in version 10