We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Column size when exported to PDF

Hi,

I'm exporting my grid to PDF. I have one column in the center of the grid wich seperates the grid in a left and right half. This column is just 20px wide.
If I now export this grid in the following way:

            DataGridPdfExportingController pdfGridExport = new DataGridPdfExportingController();
            DataGridPdfExportOption exportOption = new DataGridPdfExportOption
                                                   {
                                                       FitAllColumnsInOnePage = true,
                                                       PdfDocument            = pdfDoc,
                                                       StartPoint                  = new PointF(0, currentYPos),
                                                       ApplyGridStyle         = true,
                                                       AutoFitRowHeight   = true,
                                                       RepeatHeaders          = true
                                                   };

            pdfGridExport.ExportToPdf(_grid, exportOption);

All columns are then evenly spreaded over the page. But I want to set that "seperator column" to a very small size and only the rest should be spread.
If I set FitAllColumnsInOnePage=false the original size of all columns are retained which is good but then the whole grid doesn't fit to the page.

How can I set one specific column to a certain width and at the same time let the grid fit to the page?

Regards
Michael

3 Replies

VR Vigneshkumar Ramasamy Syncfusion Team November 19, 2018 07:29 AM UTC

Hi Michael,  
 
Thanks for contacting Syncfusion Support.  
 
We checked your query and your requirement to export the columns for the given width can be achieved by usingDataGridPdfExportOption.ExportColumnWidth. Please refer the below UG for more details on exporting with ColumnWidth.  
 
 
   
 
Regards,  
Vigneshkumar R 



MI Michael November 21, 2018 04:54 PM UTC

Hi Vigneshkumar,

thanks for your help, but that doesn't work.

If I set your suggested option:
DataGridPdfExportOption exportOption = new DataGridPdfExportOption
                                                   {
                                                       FitAllColumnsInOnePage = false,
                                                       PdfDocument            = pdfDoc,
                                                       StartPoint                  = new PointF(0, currentYPos),
                                                       ApplyGridStyle         = true,
                                                       AutoFitRowHeight   = true,
                                                       RepeatHeaders          = true,
                                                       ExportColumnWidth = true
                                                   };
the columns are exported with their original width, but then the grid doesn't fit on the page!

If I set FitAllColumnsInOnePage = true and ExportColumnWidth = true
the exportcolumnwidth option is ignored.

I want either that all columns are fit to the page with their original width relation or I want to set one specific column to a certain size only for the export.

Is this possible?

Thanks
Michael




VR Vigneshkumar Ramasamy Syncfusion Team November 22, 2018 06:42 AM UTC

Hi Micheal,  
  
Thanks for your update.   
  
Your requirement “to set one specific column to a certain size only for the export” can be achieved by usingDataGridPdfExportingController.RowExporting event. Please find the code snippet of the same below.  
  
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();  
pdfExport.RowExporting += PdfExport_RowExporting;  
  
private void PdfExport_RowExporting(object sender, DataGridRowPdfExportingEventArgs e)  
{  
    e.PdfGrid.Columns[2].Width = 200;  
}  
  
We have prepared the sample based on your requirement, you can download the same from the below link.  
 
  
Regards,  
Vigneshkumar R   


Loader.
Up arrow icon