Private Sub SetPageSize(doc As WordDocument, Width As Long, Height As Long)
Dim document As JavaObject = doc.XWPFDocument.RunMethod("getDocument", Null)
Dim body As JavaObject = document.RunMethod("getBody", Null)
If body.RunMethod("isSetSectPr", Null).As(Boolean) = False Then
body.RunMethod("addNewSectPr", Null)
End If
Dim section As JavaObject = body.RunMethod("getSectPr", Null)
If section.RunMethod("isSetPgSz", Null).As(Boolean) = False Then
section.RunMethod("addNewPgSz", Null)
End If
Dim pageSize As JavaObject = section.RunMethod("getPgSz", Null)
Dim BigInteger As JavaObject
BigInteger.InitializeStatic("java.math.BigInteger")
pageSize.RunMethod("setW", Array(BigInteger.RunMethod("valueOf", Array(Width * 20))))
pageSize.RunMethod("setH", Array(BigInteger.RunMethod("valueOf", Array(Height * 20))))
End Sub