hi
i had the same problem for long long time and after all i figured it out.
paper size has some values like height and width.
when you make a new object of PaperSize, these values are set to zero and when you set your paper to be A4, these values are zero again. so your paper size is not defined and as soon as you open pagesetup and click OK, the PaperSize is set to its true values.
so you have to set them manually. i used the pages default PaperSize and modified it instead of making a new object and my program worked correctly.
so just replace your code :
system.Drawing.Printing.PaperSize size = new PaperSize();
and put this:
system.Drawing.Printing.PaperSize size = pg.PaperSize;
in my case this solve the problem