You can setup custom document generation in your custom Apex Code with any logic or process if it’s beyond Process Builder capabilities.

Whether it is Apex Trigger or custom Apex Class, it is easy to implement custom generation of the document by following simple steps described in this document.