Implemented the buildDocument method.