The PrintingTools service and its client print widgets in the ArcGIS web APIs are intended for basic printing. For printing workflows where the web map needs to be modified or exported using advanced options, use a convert function in the Python arcpy module: ConvertWebMapToMapDocument for ArcMap and ConvertWebMapToArcGISProject for ArcGIS Pro.
Converting a web map to a map document using Python
In advanced printing scenarios, the web map JSON does not have to be sent to the PrintingTools service. Instead, you can convert the JSON into an ArcMap document (.mxd) or ArcGIS Pro Project (.aprx). To do this, use the corresponding convert function in arcpy. You can then use the resulting map or layout file in other arcpy functions, such as ExportToPDF or ExportToPNG, to prepare the map for printing. You might even choose to add the map to a map book before printing it, or switch out some of the service layers in the map with your own vector layers.
Esri offers tutorials that demonstrate the entire advanced exporting and printing workflow. These explain how to author the staged template map documents, author the Python script, create the geoprocessing service, and create the web application:
Calling your scripts from the web
Once you've written an arcpy script for printing, ArcGIS Enterprise offers geoprocessing services that allow you to expose your scripts, tools, and models as web services. This makes them easily callable from the ArcGIS web APIs.
You can choose to encapsulate your Python printing script in a geoprocessing script tool. Do a test run of your tool and then publish the result as an ArcGIS Enterprise geoprocessing service.
The easiest approach when developing this type of geoprocessing script tool is to make sure that it exposes the same parameters as the out-of-the-box PrintingTools service, or a subset thereof. The input JSON parameter is the minimum required parameter needed. If you design your service in this way, the printing widgets from Web AppBuilder for ArcGIS and printing tasks in the ArcGIS web mapping APIs and web viewers will be able to use your service without any custom coding.