How to reduce right or left margin in grid PDF Export

Please guide me how to reduce right or left margins in PDF export of data grid.



1 Reply

SK Sujith Kumar Rajkumar Syncfusion Team July 7, 2021 07:13 AM UTC

Hi Rj, 
 
Greetings from Syncfusion support. 
 
You can achieve the requirement of changing the margins for pdf export  by overriding the Grid’s processSectionExportProperties method in its created event and use the setMargins method for setting the required margin for pdf file. 
 
This is demonstrated in the below code snippet, 
 
// Grid’s created event handler 
function onCreated() { 
    var gridObj = document.getElementById('Grid').ej2_instances[0]; 
    gridObj.pdfExportModule.processSectionExportProperties = function (section, pdfExportProperties) { 
        var pdfPageSettings = new ej.pdfexport.PdfPageSettings(); 
        pdfPageSettings.orientation = ej.pdfexport.PdfPageOrientation.Portrait; 
        pdfPageSettings.size = gridObj.pdfExportModule.getPageSize('A4') 
        // Here you can set the required margin to the exported pdf file 
        pdfPageSettings.margins.setMargins(10); 
        section.setPageSettings(pdfPageSettings); 
        return section; 
    } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon