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

Doubts



Hello team,

when exporting to pdf:

1º. how to print the header only on the first page?
how to enable to view all columns in one page

Thanks

6 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team November 11, 2019 01:39 PM UTC

Hi João, 

Greetings from Syncfusion support. 

Query 1: How to print the header only on first page? 

Before proceeding on this please clarify whether you want to show Grid column header in first page or pdf headers (Title) in single page itself. 

Query 2: Need to show all columns in a page. 

Based on the count and width of the columns it will shown in a page. If you have more number of columns then you may change the page orientation to show all columns in Grid.  


If you still face the same issue then please provide how many columns that you want to bind in Grid. 

Regards, 
Thavasianand S. 



JS João Soares November 11, 2019 02:07 PM UTC

Hello team,

attached the questions thanks

Attachment: Query_1__and_Query_2_8205e15a.zip


TS Thavasianand Sankaranarayanan Syncfusion Team November 13, 2019 11:32 AM UTC

Hi João, 
 
Thanks for contacting us. 
 
Query 1 : Export the header only on the first page   
 
At present we don’t have direct support to draw the PDF header in single page alone when drawing grid. Instead of we can manually add the header to the PDF page and drawn the grid after adding the manual header.  

Query 2 : Need all the columns in a single page 
 
We can draw all the columns of grid in single PDF page by using following approaches. 

  1. You can disable the PdfGrid.style.allowHorizontalOverflow property to fit all the columns in a single page  as like stated below.
PdfGrid.style.allowHorizontalOverflow = false; 
              In this scenario the average width is considered as each column width. 

Please refer the below code and sample for information. 

<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowPdfExport="true" toolbarClick="toolbarClick" toolbar="@(new List<string>() {"PdfExport"})" allowPaging="true"> 
    --------- 
</ejs-grid> 

<script > 
    function toolbarClick(args) { 
        //Create a new PDF document 
  let pdfDocument = new ej.pdfexport.PdfDocument(); 
  let page = pdfDocument.pages.add(); 

  //Header image. 
  let headerImage = new ej.pdfexport.PdfBitmap(GetImage()); 

  //Draw the iamge. 
  page.graphics.drawImage(headerImage, 10, 0, 200, 100); 

        let titleFont = new ej.pdfexport.PdfStandardFont( 
             ej.pdfexport.PdfFontFamily.Helvetica, 
    20 
 ); 

  let contentFont = new ej.pdfexport.PdfStandardFont( 
     ej.pdfexport.PdfFontFamily.Helvetica, 
    10 
  ); 

  let brush = new ej.pdfexport.PdfSolidBrush(new ej.pdfexport.PdfColor(100, 100, 100)); 
//header content 
  page.graphics.drawString( 
    "Mountain-200", 
    titleFont, 
    null, 
    brush, 
    220, 
    0, 
    page.getClientSize().width - 220, 
    100, 
    null 
  ); 

  page.graphics.drawString( 
    "Product No: BK-M68B-38", 
    contentFont, 
    null, 
    brush, 
    220, 
    25, 
    page.getClientSize().width - 220, 
    100, 
    null 
  ); 
  page.graphics.drawString( 
    "Size: 38", 
    contentFont, 
    null, 
    brush, 
    220, 
    40, 
    page.getClientSize().width - 220, 
    100, 
    null 
  ); 
  page.graphics.drawString( 
    "Weight: 25", 
    contentFont, 
    null, 
    brush, 
    220, 
    55, 
    page.getClientSize().width - 220, 
    100, 
    null 
  ); 

  page.graphics.drawString( 
    "Price: $2,294.99", 
    contentFont, 
    null, 
    brush, 
    220, 
    70, 
    page.getClientSize().width - 220, 
    100, 
    null 
        ); 

         
        var grid = document.getElementById('Grid').ej2_instances[0]; 
         

        // create a PdfGrid  

        var pdfGrid = new ej.pdfexport.PdfGrid(); 
        pdfGrid.style.allowHorizontalOverflow = false; 
        let format = new ej.pdfexport.PdfLayoutFormat(); 
        format.paginateBounds = new ej.pdfexport.RectangleF( 
            new ej.pdfexport.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 ej.pdfexport.PointF(10, 120), format); 
        pdfDocument.save('output.pdf'); 
        pdfDocument.destroy(); 


    
    } 
    function GetImage() { 
------- 
  </script> 


Regards, 
Thavasianand S. 



JS João Soares December 2, 2019 04:21 PM UTC


hello Thavasianand,
This approach is complex.
1 = As I do in case of groupings

2 = With filter ratio

3 = Groups with sums

4 = Hidden columns

You would have a more complete example that can help me.
Thank you.
Sorry for English


JS João Soares December 4, 2019 04:12 PM UTC

?


RS Renjith Singh Rajendran Syncfusion Team December 5, 2019 01:48 PM UTC

Hi João,  
 
We have created a new incident for this query. Please follow up that incident for further updates.  
  
 
Regards, 
Renjith R.  


Loader.
Up arrow icon