Font sizes changes when exporting to PDF in Wijmo Grid

Posted by: kim on 13 September 2024, 4:21 am EST

  • Posted 13 September 2024, 4:21 am EST

    Hi, I’m trying to setup a simple PDF export from a grid.

    • I need to be able to choose which columns to include, with autoexpand and the ability change header visibility. With the code below, this works.

    But I am struggling with the format of the export.

    When I hide columns, I need the grid to autoexpand the remaining columns, not increase the font in the export. I.e if the export contains to many columns the complete text does not show, If I reduce the number of columns that I export, the export just increases the font size of the document automatically, I want the keep the font, and hopefully the remaining columns get wider and the complete text of the column is shown.

    Is there a easy way to keep the font sizes and format of the document when removing columns from the export so that the remaining columns gets wider?

    This is the code I’m using.

    var theGrid = GridAPI.GridManager.GetGridById($parameters.gridid)._provider; 
    const view = theGrid.collectionView;
    var oldPgSize = view.pageSize;
    var oldPgIndex = view.pageIndex;
    
    if($parameters.PrintAllPages=true){
        //gjør dette for å sette ny pageindex for å laste ned hele griden (med paginering)
        theGrid.beginUpdate();
        // 0 her betyr alle
        view.pageSize = 0;
        }
    
    theGrid.autoSizeColumns();
    theGrid.headersVisibility = 1;
    
    
    wijmo.grid.pdf.FlexGridPdfConverter.export(theGrid, $parameters.HeaderText.replace(' ', '') + '_'+$parameters.TitleText.replace(' ', '_')+'.pdf', {
       scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth,
       maxPages: 99,
      
       documentOptions: {
        info: {title: $parameters.HeaderText },
        pageSettings: {
            layout : $parameters.LandscapeLayout,
            size : 3
            },
        header: { declarative: { text: $parameters.HeaderText } },
        footer: { declarative: { text: '\t&[Page]\\&[Pages]' } },
        
       },
          styles: {
          cellStyle: {
             backgroundColor: '#ffffff',
             borderColor: '#ffffff',
             font: {
                size: 15
              }
          },
          headerCellStyle: {
             backgroundColor: '#ffffff',
             font: {
                size: 15
              }
          }
       },
    });
    
    if($parameters.PrintAllPages=true){
                view.pageSize = oldPgSize;
                view.moveToPage(oldPgIndex);
                theGrid.endUpdate();
                }
    
    theGrid.headersVisibility = 3;
  • Posted 16 September 2024, 2:20 am EST

    Hi Kim,

    It seems you are auto-sizing the flexgrid columns just before the export using the ‘autoSizeColumns’ method, which might be causing these results. Auto-sizing the columns resets the columns width to a fix number that fits the column content, due to which the same width of the columns is exported in the PDF file. If you want to auto-expand the columns to fit the available page width, you’ll have to avoid auto-sizing the columns. You can use the ‘recalculateStarWidths’ option to recalculate the column widths according to the ‘*’ sizing during the export, if needed. This property will not have any effect if columns are auto-sized before export. Here’s the API link for more information about this option - https://developer.mescius.com/wijmo/api/interfaces/wijmo_grid_pdf.iflexgridexportsettings.html#recalculatestarwidths

    Here’s a sample for your reference - https://jscodemine.mescius.io/share/axGRSlle_US3YicqHOaBTA/

    We are not able to replicate the issue with automatic font size increase in PDF export, if your issue is not resolved with the above solution, please modify the above sample to replicate your issue and share it with us, so that we can have a better understanding of the issue and assist you accordingly.

    In case, if there is something we missed, please let us know.

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels