PDF Export Stop Text Wrap

Hello,

I would like it so when a grid exports to PDF the column adjust its size to content, so text does not wrap. Is this possible? Below is an image of what is happening currently.






Thanks,

Charles


27 Replies 1 reply marked as answer

BS Balaji Sekar Syncfusion Team January 25, 2022 11:42 AM UTC

Hi Charles, 

Greetings from the Syncfusion support. 

Based on your query you need to break the overlapping text when PDF exporting on the Grid and we suggest you to use allowHorizontalOverflow  as true then pass this property to pdfExport method it will wrap the overlapping text on Grid cells. 

Please refer the below code example and sample for more information 
toolbarClick(argsClickEventArgs): void { 
      case 'PDF Export': 
        this.grid.pdfExport({ allowHorizontalOverflow: true });// Defines the overflow of columns for the pdf grid 
 
        break; 
    } 
  } 


Please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 



CE Charles Eichelberger replied to Balaji Sekar January 25, 2022 01:54 PM UTC

Hello this option breaks the columns across multiple pages. I need all the columns to be on one page still. The columns should just not wrap the text.


Thanks,

Charles



RR Rajapandi Ravi Syncfusion Team January 26, 2022 10:23 AM UTC

Hi Charles, 

Currently, we have forwarded this query to our concern team, and we will update you the details on 31st Jan 2022. Until then we appreciate your patience. 

Regards, 
Rajapandi R 



CE Charles Eichelberger replied to Rajapandi Ravi January 26, 2022 02:56 PM UTC

Thank you for the update. I look forward to more information on Jan. 31st


Thanks,

Charles



RR Rajapandi Ravi Syncfusion Team January 27, 2022 02:26 PM UTC

Hi Charles, 

Thanks for your patience 

Based on your query you want to export all the columns in the single page without splitting them into next page. Based on that we have prepared sample in that we have used the allowHorizontalOverflow to export all the columns in a single page. For your convenience we have attached the sample so please refer them for your reference. 


toolbarClick(args: ClickEventArgs): void { //toolbar click event 
    if (args.item.text === 'PDF Export') { 
      let pdfDocument = new PdfDocument(); 
      let page = pdfDocument.pages.add(); 
      let contentFont = new PdfStandardFont(PdfFontFamily.Helvetica, 10); 

      var grid = (document.getElementById('Grid') as any).ej2_instances[0]; 
      // create a PdfGrid 

      var pdfGrid = new PdfGrid(); 
      pdfGrid.style.allowHorizontalOverflow = false; 
      let format = new PdfLayoutFormat(); 
      format.paginateBounds = new RectangleF( 
        new PointF(0, 0), 
        page.getClientSize() 
      ); 
      var collength = grid.columns.length; 
      pdfGrid.columns.add(collength); 

      // add header 
      pdfGrid.headers.add(1); 

      var pdfGridHeader = pdfGrid.headers.getHeader(0); 
      for (let j = 0; j < collength; j++) { 
        pdfGridHeader.cells.getCell(j).value = grid.columns[j].headerText; 
      } 
      let pdfGridRow1 = []; 
      // add rows 
      for (let k = 0; k < grid.dataSource.length; k++) { 
        pdfGridRow1[k] = pdfGrid.rows.addRow(); 
      } 
      for (let k = 0; k < grid.dataSource.length; k++) { 
        for (let r = 0; r < grid.columnModel.length; r++) { 
          pdfGridRow1[k].cells.getCell(r).value = 
            grid.dataSource[k][grid.columnModel[r].field].toString(); 
        } 
      } 
      // draw the PdfGrid 
      pdfGrid.draw(page, new PointF(0, 0), format); 
      pdfDocument.save('output.pdf'); 
      pdfDocument.destroy(); 
    } 
  } 



Regards, 
Rajapandi R 



CE Charles Eichelberger replied to Rajapandi Ravi January 27, 2022 02:57 PM UTC

Hi,


The proposed solution does not work with stacked headers as it only uses the top level of headers.


Thanks,

Charles



CE Charles Eichelberger replied to Charles Eichelberger January 27, 2022 03:11 PM UTC

Also the text still wraps. I want all the columns to be on one page but also no text wrapping for the columns.



RR Rajapandi Ravi Syncfusion Team January 28, 2022 02:23 PM UTC

Hi Charles, 

Thanks for the update 

By default, while exporting a pdf export the Grid will auto adjust in the pdf layout, to render all columns in single page, the Grid cell will adjust based on pdf cell. So, when the content overflow in the pdf cell it will automatically wrap the text and adjust the content. It was the default behavior.  

From your update, we could see that you are using a stacked header columns in the Grid. So based on your query we have prepared a sample and we suggest you use the below way to achieve your requirement. Please refer the below code example and sample for more information. 


  toolbarClick(args: any): void { //toolbar click event 
    if (args.item.text === 'PDF Export') { 
              // create a new PDF document 
              let pdfDocument = new PdfDocument(); 
              // add a page 
              let page = pdfDocument.pages.add(); 
              // set the font 
              let font = new PdfStandardFont(2, 10); 
              // create black brush 
              let brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); 
       
              var totalGrid = document.getElementsByClassName('e-grid'); 
              for (var g = 0; g < totalGrid.length; g++) { 
                  var gridI = (totalGrid[g] as any).ej2_instances[0]; 
                  // create a PdfGrid 
                  let pdfGrid = new PdfGrid(); 
                  pdfGrid.style.allowHorizontalOverflow = false;  
                  // add columns 
                  var columns = gridI.getColumns(); 
                  pdfGrid.columns.add(columns.length); 
       
                  // add headers 
                  var headers = gridI.columns; 
                  var secondLevelHeader = []; 
                  var firstLevelHeader = []; 
                  for (var s = 0; s < headers.length; s++) { 
                      firstLevelHeader.push(headers[s].headerText) 
                      if (headers[s].columns) { 
                          var stackedHeader = true; // enable the stackedHeader flag variable if the grid have stacked header. 
                          for (var k = 0; k < headers[s].columns.length; k++) { 
                              secondLevelHeader.push(headers[s].columns[k].headerText) 
                          } 
                      } 
                  } 
                  if (stackedHeader) { 
                      pdfGrid.headers.add(2); 
                  } else { 
                      pdfGrid.headers.add(1); 
                  } 
                  var secondLevelHeaderOrder = []; 
                  for (var h = 0; h < (pdfGrid.headers as any).rows.length; h++) { 
                      if (h == 0) { 
                          let pdfGridHeader1 = pdfGrid.headers.getHeader(h); 
                          var firstLevelHeaderOrder = 0; 
                          for (var n = 0; n < firstLevelHeader.length; n++) { 
                              if (headers[n].columns) { 
                                  var columnSpanLength = headers[n].columns.length; 
                                  let secondLevelHeaderOrderIndex = firstLevelHeaderOrder; 
                                  for (var t = 0; t < columnSpanLength; t++) { 
                                      secondLevelHeaderOrder.push(secondLevelHeaderOrderIndex + t); 
                                  } 
                                  pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).value = firstLevelHeader[n]; 
                                  //Apply column span for first level stacked header 
                                  pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).columnSpan = columnSpanLength; 
                                  firstLevelHeaderOrder = firstLevelHeaderOrder + columnSpanLength 
                              } else if (stackedHeader) { 
                                  pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).value = firstLevelHeader[n]; 
                                  //Apply row span for first level normal header if grid have stacked header 
                                  pdfGridHeader1.cells.getCell(firstLevelHeaderOrder).rowSpan = 2; 
                                  firstLevelHeaderOrder = firstLevelHeaderOrder + 1 
                              } else { 
                                  pdfGridHeader1.cells.getCell(n).value = firstLevelHeader[n]; 
                              } 
       
                          } 
       
                      } else { 
                          let pdfGridHeader2 = pdfGrid.headers.getHeader(h); 
                          for (var st = 0; st < secondLevelHeader.length; st++) { 
                              pdfGridHeader2.cells.getCell(secondLevelHeaderOrder[st]).value = secondLevelHeader[st]; 
                          } 
                      } 
                  } 
                  stackedHeader = false 
                  // add rows 
                  var data = gridI.dataSource; 
                  for (let i = 0; i < data.length; i++) { 
                      let pdfGridRow = pdfGrid.rows.addRow(); 
                      for (let j = 0; j < columns.length; j++) { 
                          var field = columns[j].field; 
                          if (field) { 
                              pdfGridRow.cells.getCell(j).value = data[i][field].toString(); 
                          } 
       
                      } 
                  } 
                  if (g == 0) { 
                      // drawing a grid 
                      var gridResult = pdfGrid.draw( 
                          page, 
                          new PointF(0, 0) 
                      ); 
                  } else { 
                      let layoutFormat = new PdfGridLayoutFormat(); 
                      layoutFormat.layout = 0; //PdfLayoutType.Paginate; 
                      layoutFormat.break = 0; //PdfLayoutBreakType.FitPage; 
                      // drawing a grid based on PdfGridLayoutResult value 
                      gridResult = pdfGrid.draw( 
                          gridResult.page, 
                          new PointF(0, gridResult.bounds.y + gridResult.bounds.height + 30), 
                          layoutFormat 
                      ); 
                  } 
              } 
              //Save the document. 
              pdfDocument.save('MultipleGrid_Result.pdf'); 
              pdfDocument.destroy(); 
          }   
  } 


Screenshot: 

 

Regards, 
Rajapandi R 



CE Charles Eichelberger replied to Rajapandi Ravi January 28, 2022 02:53 PM UTC

By default, while exporting a pdf export the Grid will auto adjust in the pdf layout, to render all columns in single page, the Grid cell will adjust based on pdf cell. So, when the content overflow in the pdf cell it will automatically wrap the text and adjust the content. It was the default behavior. 

I understand that by default it will warp the text I do not want it to.




CE Charles Eichelberger replied to Charles Eichelberger January 28, 2022 03:08 PM UTC

We used another library for pdf exports  in the past and it was able to fit all the columns on one page without the columns text wrapping.  Below is an example 







With Syncfusion the pdf can fit all the columns onto one page but the columns will wrap the text which looks ugly. We do not want this behavior. Below is an example of that.





thanks,

Charles







RR Rajapandi Ravi Syncfusion Team January 31, 2022 01:24 PM UTC

Hi Charles, 

Currently we are checking the feasibility to achieve your requirement. So, we need some more time to validate this. We will update you the details on or before 2nd Feb 2022. Until then we appreciate your patience. 

Regards,
Rajapandi R 



CE Charles Eichelberger replied to Rajapandi Ravi January 31, 2022 09:43 PM UTC

HI,


Thanks for the update.



PS Pavithra Subramaniyam Syncfusion Team February 1, 2022 12:05 PM UTC

Hi Charles, 
 
We need some more details for further validation. So could you please share the below details that will be helpful for us to provide a better solution as early as possible. 
 
  1. Share the Grid column definition for checking the width
  2. Share the export properties passed along with the pdfExport method
  3. Will setting the pageSize (like A3, A2, A1)and fontSize properties achieve your requirement?
 
Regards, 
Pavithra S 



CE Charles Eichelberger replied to Pavithra Subramaniyam February 1, 2022 02:56 PM UTC

Hi,


Attached is all the code I am using for this. As for page size we CAN NOT change that. We CAN however change font size.


Attachment: exportdemo_69d35ef.zip


PS Pavithra Subramaniyam Syncfusion Team February 2, 2022 02:37 PM UTC

Hi Charles, 

Thanks for sharing the details. 

We are checking the feasibility with the provided details and will update further on Feb 04th, 2022. Until then we appreciate your patience. 

Regards, 
Pavithra S  



CE Charles Eichelberger replied to Pavithra Subramaniyam February 2, 2022 02:38 PM UTC

Thank you for the update 



SK Sujith Kumar Rajkumar Syncfusion Team February 7, 2022 10:52 AM UTC

Hi Charles, 
 
Thanks for your patience. 
 
Your requirement of exporting all the Grid columns in one page without wrapping can be achieved by setting the required width to the Grid columns(so that the content is not wrapped) and then overriding the Grid pdf export module’s processSectionExportproperties method where the width and height of the pdf grid is modified based on the content size. This can be done in the Grid’s created event as demonstrated in the below code snippet, 
 
// Grid’s created event handler 
created() { 
    (this.grid.pdfExportModule as any).processSectionExportProperties = function (section, pdfExportProperties) { 
        var pdfPageSettings = new PdfPageSettings(); 
        var doc = this.pdfDocument; 
        pdfPageSettings.margins.all = 0; 
        // The Grid size is retrieved 
        var gridResult = this.parent.element.getBoundingClientRect(); 
        // The pdf size is calculated from the grid size 
        // You can customize the below values based on your requirement for modifying the  page size 
        var result = new SizeF(gridResult.width + 300, gridResult.height + 300); 
        // The calculated size is set as the pdf document size and returned 
        pdfPageSettings.size = new SizeF(result.width, result.height); 
        section.setPageSettings(pdfPageSettings); 
        return section; 
    } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
Let us know if you have any concerns 
 
Regards, 
Sujith R 


Marked as answer

CE Charles Eichelberger replied to Sujith Kumar Rajkumar February 7, 2022 02:27 PM UTC

Hi,


Thank you so much this has fixed all my problems!



RR Rajapandi Ravi Syncfusion Team February 8, 2022 05:57 AM UTC

Hi Charles, 

We are happy to hear that the provided solution work fine at your end. 

Please get back to us if you need further assistance. 

Rajapandi R 




CE Charles Eichelberger replied to Rajapandi Ravi February 11, 2022 03:56 PM UTC

Hi,


After some more testing this does work well for displaying the pdf correctly however if you go to print the pdf out it cuts off some of the columns. Below is an image of what happens.





RR Rajapandi Ravi Syncfusion Team February 14, 2022 02:00 PM UTC

Hi Charles, 

Thanks for the update 

By default, the browser uses A4 as page size option to print pages and to adapt the size of the page the browser print preview will auto-hide the overflowed contents. Hence grid with large number of columns will cut off to adapt the print page. 

To show large number of columns when printing, adjust the scale option from print option panel based on your content size. We have already discussed this query in our documentation, which can be accessed from the below link, 


Regards, 
Rajapandi R 



CE Charles Eichelberger replied to Rajapandi Ravi February 14, 2022 02:30 PM UTC

Hi,


Unfortunately this is not an option as we can not rely on our customers doing this every time they need to print some



RR Rajapandi Ravi Syncfusion Team February 15, 2022 02:02 PM UTC

Hi Charles, 

Thanks for the update 

Currently we are checking the feasibility to achieve your requirement. So, we need some more time to validate this. We will update you the details on or before 17th Feb 2022. Until then we appreciate your patience. 

Rajapandi R 




CE Charles Eichelberger replied to Rajapandi Ravi February 15, 2022 07:27 PM UTC

Hi,


Thank you for the update I appreciate all the work that has been put into this item.



RR Rajapandi Ravi Syncfusion Team February 16, 2022 04:02 PM UTC

Hi Charles, 

By default, the window print size was ISO dimensions: 210mm x 297mm. When the content exceeds with the window print size it will automatically cut off to adapt the print page. This was the default behavior of print.  

When displaying the large number of columns, the print window can adapt with its default size. So, we suggest you export the PDF document with your requirement as we recommend this link and then print the exported PDF to achieve your requirement. 

Regards, 
Rajapandi R 



CE Charles Eichelberger replied to Rajapandi Ravi February 18, 2022 07:22 PM UTC

Hi,


As discussed above this does not fix our problems as text will still wrap. This does fix it, but when printing it cuts columns off.





RR Rajapandi Ravi Syncfusion Team February 21, 2022 11:50 AM UTC

Hi Charles, 

By default, the Grid with large number of columns will cut off to adapt the print page. This was the default behavior of print.  

To overcome the problem, we suggest you to export the PDF document as we suggested in this link and then print the exported PDF to achieve your requirement. For your convenience we have demonstrate the same in the video demo, please refer them for your reference. 


Regards, 
Rajapandi R 



Loader.
Up arrow icon