Add header to export PDF AJAX

I have recently purchased the gantt chart library with the PDF export module docker image. I am a newbie to this.

I have added a specific header using dataProcessor’s setTransactionMode in order for the backend API to accept the AJAX call. That fixed the issue for interactions on gantt chart. Now, I am having the same issue with using export to PDF since it’s not using dataProcessor but directly doing a form submit. How would I add the additional header for this case?


PS: If you are curious, the header is X-CSRFToken

Currently there is no built-in way to add custom parameters to the export request form.
The only solution I can suggest is to override a private method that creates a form for the export and add an input there.
Try adding this code somewhere after dhtmlxgantt.js and :

function patchExport(gantt){
var createForm = gantt._create_hidden_form;

gantt._create_hidden_form = function(){
var formContainer =;
var form = formContainer.querySelector(“form”);
var csrfInput = document.createElement(“input”);
csrfInput.type = “hidden”; = “csrf”;
csrfInput.value = “CSRF KEY”;
return formContainer;


Thank you Ramil. This solution wouldn’t work because my API is looking for CSRF on the Request header and the override you have suggested adds it to form data.

I am thinking of overriding the method to do a $.ajax and inside success method do a and pass the PDF response to it. With using $.ajax, I can add custom headers by using the header options

Unfortunately, there is no easy solution for that. So the method with $.ajax calls should help you.