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 the ConvertWebMapToMapDocument function in the Python arcpy.mapping module.
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 MXD. To do this, use the Python function arcpy.mapping.ConvertWebMapToMapDocument. You can then use the resulting MXD in other arcpy.mapping 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. These techniques are described in the ConvertWebMapToMapDocument reference topic.
There are also some 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.mapping script for printing, how do you use it from your web application? ArcGIS Server 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.
Once you have a Python script that prepares the map for printing, you can choose to encapsulate it in a geoprocessing script tool. Do a test run of your tool and then publish the result as an ArcGIS Server 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 the ArcGIS web mapping APIs and web viewers will be able to use your service without any custom coding by you.