FlexGrid
Tree view
The sample demonstrates how to export FlexGrid content to a PDF file. Tree view support and font embedding.
Features
Description
This sample shows how the tree view feature of the FlexGrid is supported in the FlexGridPdfConverter.
In this sample, FlexGrid uses font Fira and two typefaces, FiraSans-Regular.ttf and FiraSans-Bold.ttf, are embeded into the document. The FiraSans-Bold.ttf (boldface) typeface is used to display the header cells, and the FiraSans-Regular.ttf typeface is used for rest of the content.
You can use the FlexGridPdfConverter, a PDFKit-based JavaScript library, to export FlexGrid to PDF (Portable Document Format) without using any server-side code.
To export a FlexGrid, you need to use the FlexGridPdfConverter.export function that takes the following arguments:
- A FlexGrid instance.
- Name of the file to export.
- Export settings.
In this sample, you can change the following export settings using the menus above:
- scaleMode: Determines how the FlexGrid content should be scaled in order to fit the page.
- orientation: Determines the orientation of pages.
- exportMode: Determines which part of the FlexGrid should be exported (all of the data or only the current selection).
You can also specify some security settings, such as user password, owner password and permissions, to protect the exported PDF content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using MvcExplorer.Models; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using System.Linq; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { private static IList<ITreeItem> pdfExportTreeViewData = null ; public ActionResult PDFExportTreeView() { if (pdfExportTreeViewData == null ) { pdfExportTreeViewData = Folder.Create(Startup.Environment.WebRootPath).Children; } ViewBag.TreeViewData = pdfExportTreeViewData; return View(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | @using C1.Web.Mvc.Grid @ { IList< ITreeItem > treeViewData = ViewBag.TreeViewData; } @section Styles{ < style > . fixed -top { z-index: 999; position: fixed ; top: 0px; } .reduce { padding-bottom: 0px; } </ style > } @section Scripts{ <script> var treeViewGrid, exportSettings, settingsDiv, securitySettingsDiv; c1.documentReady( function () { treeViewGrid = wijmo.Control.getControl( "#treeFlexGrid" ); settingsDiv = document.getElementById( "exportSettingsDiv" ); securitySettingsDiv = document.getElementById( "securitySettingsDiv" ); exportSettings = { exportMode: wijmo.grid.pdf.ExportMode.All, orientation: wijmo.pdf.PdfPageOrientation.Portrait, scaleMode: wijmo.grid.pdf.ScaleMode.ActualSize, version: "v1_4" , }; }); function setScaleMode(menu) { menu.header = "@(FlexGridRes.PDFExport_ScaleMode): <b>" + menu.selectedItem.Header + "</b>" ; exportSettings.scaleMode = wijmo.grid.pdf.ScaleMode[menu.selectedItem.Header]; } function setOrientation(menu) { menu.header = "@(FlexGridRes.PDFExport_Orientation): <b>" + menu.selectedItem.Header + "</b>" ; exportSettings.orientation = wijmo.pdf.PdfPageOrientation[menu.selectedItem.Header]; } function setExportMode(menu) { menu.header = "@(FlexGridRes.PDFExport_ExportMode): <b>" + menu.selectedItem.Header + "</b>" ; exportSettings.exportMode = wijmo.grid.pdf.ExportMode[menu.selectedItem.Header]; } function setPermissionPrinting(menu) { menu.header = "@FlexGridRes.PDFExport_Printing: <b>" + menu.selectedItem.Header + "</b>" ; exportSettings.permissionPrinting = menu.selectedItem.Header; } function setVersion(menu) { menu.header = "PDF version: <b>" + menu.selectedItem.Header + "</b>" ; switch (menu.selectedItem.Header) { case "1.3" : exportSettings.version = "v1_3" ; break ; case "1.4" : exportSettings.version = "v1_4" ; break ; case "1.5" : exportSettings.version = "v1_5" ; break ; case "1.6" : exportSettings.version = "v1_6" ; break ; case "1.7" : exportSettings.version = "v1_7" ; break ; case "1.7 ExtensionLevel 3" : exportSettings.version = "v1_7Ext3" ; break ; } } function getPassword(user) { return document.querySelector( '#tb' + user + 'Password' ).value; } function getPermission(permissionName) { if (permissionName == 'Printing' ) { return exportSettings.permissionPrinting || 'NotAllowed' ; } else { return document.querySelector( '#cb' + permissionName). checked ; } } function exportTreeViewGrid() { wijmo.grid.pdf.FlexGridPdfConverter.export(treeViewGrid, 'FlexGrid.pdf' , { maxPages: 10, exportMode: exportSettings.exportMode, scaleMode: exportSettings.scaleMode, embeddedFonts: [{ source: '@(Url.Content("~/Content/fonts/fira/FiraSans-Regular.ttf"))' , name: 'fira' , style: 'normal' , weight: 'normal' , sansSerif: true }, { source: '@(Url.Content("~/Content/fonts/fira/FiraSans-Bold.ttf"))' , name: 'fira' , style: 'normal' , weight: 'bold' , sansSerif: true }], documentOptions: { userPassword: getPassword( 'User' ), ownerPassword: getPassword( 'Owner' ), version: exportSettings.version, permissions: { annotating: getPermission( 'Annotating' ), contentAccessibility: getPermission( 'ContentAccessibility' ), copying: getPermission( 'Copying' ), documentAssembly: getPermission( 'DocumentAssembly' ), fillingForms: getPermission( 'FillingForms' ), modifying: getPermission( 'Modifying' ), printing: getPermission( 'Printing' ) }, pageSettings: { layout: exportSettings.orientation }, header: { declarative: { text: '&[Page]\\&[Pages]\theader\t&[Page]\\&[Pages]' } }, footer: { declarative: { text: '&[Page]\\&[Pages]\tfooter\t&[Page]\\&[Pages]' } }, info: { author: 'C1' , title: 'PdfDocument sample' , keywords: 'PDF, C1, sample' , subject: 'PdfDocument' } }, styles: { cellStyle: { backgroundColor: '#ffffff' , borderColor: '#c6c6c6' , font: { family: 'fira' } }, altCellStyle: { backgroundColor: '#f9f9f9' }, groupCellStyle: { backgroundColor: '#dddddd' }, headerCellStyle: { backgroundColor: '#eaeaea' } } }); } </script> } < div class = "copy well" id = "exportSettingsDiv" > < b > @Html .Raw(FlexGridRes.PDFExport_ExportSettings)</ b > < c1-menu header = "@(FlexGridRes.PDFExport_ScaleMode + " <b>ActualSize</ b > ")" item-clicked= "setScaleMode" > < c1-menu-item header = "ActualSize" ></ c1-menu-item > < c1-menu-item header = "PageWidth" ></ c1-menu-item > < c1-menu-item header = "SinglePage" ></ c1-menu-item > </ c1-menu > < c1-menu header = "@(FlexGridRes.PDFExport_Orientation + " <b>Portrait</ b > ")" item-clicked= "setOrientation" > < c1-menu-item header = "Portrait" ></ c1-menu-item > < c1-menu-item header = "Landscape" ></ c1-menu-item > </ c1-menu > < c1-menu header = "@(FlexGridRes.PDFExport_ExportMode + " <b>All</ b > ")" item-clicked= "setExportMode" > < c1-menu-item header = "All" ></ c1-menu-item > < c1-menu-item header = "Selection" ></ c1-menu-item > </ c1-menu > < div id = "securitySettingsDiv" > < p ></ p > < b > @Html .Raw(FlexGridRes.PDFExport_SecuritySettings)</ b > < div class = "panel-body reduce" > < div class = "row" > < div class = "col-sm-3" > < input type = "text" id = "tbUserPassword" class = "form-control" placeholder = "@FlexGridRes.PDFExport_UserPassword" /> </ div > < div class = "col-sm-3" > < input type = "text" id = "tbOwnerPassword" class = "form-control" placeholder = "@FlexGridRes.PDFExport_OwnerPassword" /> </ div > </ div > < br /> < div class = "row" > < div class = "col-sm-3" > < c1-menu header= "PDF version: <b>1.4</b>" item-clicked= "setVersion" selected-index= "1" > < c1-menu-item header = "1.3" ></ c1-menu-item > < c1-menu-item header = "1.4" ></ c1-menu-item > < c1-menu-item header = "1.5" ></ c1-menu-item > < c1-menu-item header = "1.6" ></ c1-menu-item > < c1-menu-item header = "1.7" ></ c1-menu-item > < c1-menu-item header = "1.7 ExtensionLevel 3" ></ c1-menu-item > </ c1-menu > </ div > </ div > < div class = "panel-body reduce" > < div class = "row" > < div class = "col" > < b > @FlexGridRes .PDFExport_Permissions</ b > (< i > @FlexGridRes .PDFExport_PermissionsNote</ i >) </ div > </ div > < div class = "row" > < div class = "col-sm-3" > < div class = "checkbox" > < label >< input type = "checkbox" id = "cbAnnotating" /> @FlexGridRes .PDFExport_Annotating</ label > </ div > < div class = "checkbox" > < label >< input type = "checkbox" id = "cbContentAccessibility" /> @FlexGridRes .PDFExport_ContentAccessibility</ label > </ div > < div class = "checkbox" > < label >< input type = "checkbox" id = "cbCopying" /> @FlexGridRes .PDFExport_Copying</ label > </ div > < div class = "checkbox" > < label >< input type = "checkbox" id = "cbDocumentAssembly" /> @FlexGridRes .PDFExport_DocumentAssembly</ label > </ div > < div class = "checkbox" > < label >< input type = "checkbox" id = "cbFillingForms" /> @FlexGridRes .PDFExport_FillingForms</ label > </ div > < div class = "checkbox" > < label >< input type = "checkbox" id = "cbModifying" /> @FlexGridRes .PDFExport_Modifying</ label > </ div > </ div > </ div > < c1-menu header = "@(FlexGridRes.PDFExport_Printing + " <b>NotAllowed</ b > ")" item-clicked= "setPermissionPrinting" > < c1-menu-item header = "NotAllowed" ></ c1-menu-item > < c1-menu-item header = "AllowLowResolution" ></ c1-menu-item > < c1-menu-item header = "AllowHighResolution" ></ c1-menu-item > </ c1-menu > </ div > </ div > </ div > </ div > < button class = "btn btn-default" onclick = "exportTreeViewGrid()" > @Html .Raw(FlexGridRes.PDFExport_Export)</ button > < br /> < c1-flex-grid id = "treeFlexGrid" class = "grid custom-flex-grid" child-items-path = "Children" auto-generate-columns = "false" allow-resizing = "None" headers-visibility = "Column" selection-mode = "ListBox" > < c1-items-source source-collection = "treeViewData" ></ c1-items-source > < c1-flex-grid-column binding = "Header" width = "*" ></ c1-flex-grid-column > < c1-flex-grid-column binding = "Size" width = "80" ></ c1-flex-grid-column > </ c1-flex-grid > @section Summary{ < p > @Html .Raw(FlexGridRes.PDFExport_Summary) @Html .Raw(FlexGridRes.PDFExport_TreeViewSupportAndFontEmbedding).</ p > } @section Description{ < p >< b > @Html .Raw(FlexGridRes.PDFExport_Text5)</ b ></ p > < p >< b > @Html .Raw(FlexGridRes.PDFExport_Text6)</ b ></ p > < p > @Html .Raw(FlexGridRes.PDFExport_Text0)</ p > < p > @Html .Raw(FlexGridRes.PDFExport_Text1)</ p > < ul > < li > @Html .Raw(FlexGridRes.PDFExport_Li1)</ li > < li > @Html .Raw(FlexGridRes.PDFExport_Li2)</ li > < li > @Html .Raw(FlexGridRes.PDFExport_Li3)</ li > </ ul > < p > @Html .Raw(FlexGridRes.PDFExport_Text2)</ p > < ul > < li > @Html .Raw(FlexGridRes.PDFExport_Li4)</ li > < li > @Html .Raw(FlexGridRes.PDFExport_Li5)</ li > < li > @Html .Raw(FlexGridRes.PDFExport_Li6)</ li > </ ul > < p > @Html .Raw(FlexGridRes.PDFExport_Text8)</ p > } |