製品版のみの機能
Infragistics Documents - 概要
Infragistics® Document Engine は、Portable Document Format (PDF) および Open XML Paper Specification (XPS) 文書を作成するための Microsoft® .NET API を提供します。
このサンプルは CTP 機能を使用しています。製品版では、API や動作が変更される場合があります。
このサンプルは、より大きい画面サイズのためにデザインされました。
モバイル デバイスで画面を回転、フル サイズ表示、またはその他のデバイスにメールで送信します。
たとえば、.NET アプリケーションでこのアセンブリを使用してこの文書形式でグリッド データを生成できます。
コード ビュー
クリップボードへコピー
@using Infragistics.Web.Mvc @using IgniteUI.SamplesBrowser.Models @model IQueryable<IgniteUI.SamplesBrowser.Models.Northwind.Order> <!DOCTYPE html> <html> <head> <title></title> <!-- Ignite UI for jQuery Required Combined CSS Files --> <link href="http://cdn-na.infragistics.com/igniteui/2024.1/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" /> <link href="http://cdn-na.infragistics.com/igniteui/2024.1/latest/css/structure/infragistics.css" rel="stylesheet" /> <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script> <!-- Ignite UI for jQuery Required Combined JavaScript Files --> <script src="http://cdn-na.infragistics.com/igniteui/2024.1/latest/js/infragistics.core.js"></script> <script src="http://cdn-na.infragistics.com/igniteui/2024.1/latest/js/infragistics.lob.js"></script> <style type="text/css"> .export-pdf-xps-sample fieldset { margin: 5px; margin-bottom: 10px; padding: 10px; border: 1px solid #CCCCCC; } .export-pdf-xps-sample fieldset label { display: block; margin-bottom: 3px; } .export-pdf-xps-sample fieldset input { margin-bottom: 5px; float: left; clear: left; } .export-pdf-xps-sample fieldset label { float: left; width: 130px; padding-top: 2px; } .export-pdf-xps-sample fieldset fieldset { display: inline-block; vertical-align: middle; width: auto; } #grid1_container { margin: 15px auto; } .export-pdf-xps-sample .button-container { position: relative; display: inline-block; vertical-align: middle; height: auto; } </style> </head> <body> @using(Html.BeginForm()) { <div class="export-pdf-xps-sample"> <fieldset> <legend>エクスポート オプション</legend> <fieldset> <legend>エクスポート形式</legend> <input type="radio" name="pageFormat" id="pageFormatPdf" value="pdf" checked="checked" /> <label for="pageFormatPdf">PDF 形式</label> <input type="radio" name="pageFormat" id="pageFormatXps" value="xps" /> <label for="pageFormatXps">XPS 形式</label> </fieldset> <fieldset> <legend>エクスポートの方向</legend> <input type="radio" name="pageOrientation" id="pageOrientationPor" value="portrait" checked="checked" /> <label for="pageOrientationPor">縦</label> <input type="radio" name="pageOrientation" id="pageOrientationLan" value="landscape" /> <label for="pageOrientationLan">横</label> </fieldset> <fieldset> <legend>エクスポートのタイプ</legend> <input type="radio" name="exportType" id="currentPage" value="currentPage" checked="checked" /> <label for="currentPage">現在のページ</label> <input type="radio" name="exportType" id="allPages" value="allPages" /> <label for="allPages">すべてのページ</label> </fieldset> <div class="button-container"> <input id="btnSubmit" type="submit" value="エクスポート" /> </div> </fieldset> </div> <script type="text/javascript"> $(function () { var grid = $("#grid1"), pageSize = $("#pageSize"), pageNumber = $("#pageNumber"); pageNumber.val(0); pageSize.val(0); grid.on("iggridrendered", function (e, ui) { pageSize.val(grid.igGridPaging("option", "pageSize")); pageNumber.val(grid.igGridPaging("option", "currentPageIndex")); }); grid.on("iggridpagingpageindexchanged", function (e, ui) { pageNumber.val(ui.pageIndex); }); grid.on("iggridpagingpagesizechanged", function (e, ui) { pageSize.val(ui.pageSize); pageNumber.val(0); }); }); </script> @(Html.Infragistics().Grid(Model).ID("grid1") .PrimaryKey("OrderID") .AutoGenerateColumns(false) .Columns(column => { column.For(x => x.OrderID).HeaderText("注文 ID").DataType("number"); column.For(x => x.ContactName).HeaderText("名前"); column.For(x => x.ShipAddress).HeaderText("配送先住所"); column.For(x => x.OrderDate).HeaderText("注文日"); }).Features(features => { features.Paging(); }).Height("500").Width("100%").DataSourceUrl(Url.Action("PagingGetData")).DataBind().Render()) <input type="hidden" name="pageSize" id="pageSize" value="" /> <input type="hidden" name="pageNumber" id="pageNumber" value="" /> } </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; #region PDF_XPS Document Exporting using Infragistics.Web.Mvc; using Infragistics.Documents.Reports.Graphics; using Infragistics.Documents.Reports.Report; using Infragistics.Documents.Reports.Report.Band; using Infragistics.Documents.Reports.Report.Preferences.Printing; using Infragistics.Documents.Reports.Report.Section; using Infragistics.Documents.Reports.Report.Table; using Infragistics.Documents.Reports.Report.Text; using IgniteUI.SamplesBrowser.Models.Repositories; using IgniteUI.SamplesBrowser.Models.Northwind; #endregion namespace IgniteUI.SamplesBrowser.Controllers { public class InfragisticsDocumentsController : Controller { private IEnumerable<Order> orders = null; // Orders data private IEnumerable<Order> Orders{ get { try { if (orders == null) orders = RepositoryFactory.GetOrderRepository().Get().Take(100).AsQueryable(); return orders; } catch (Exception) { return new List<Order>().AsQueryable(); } } } // // GET: /InfragisticsDocuments/ [ActionName("create-pdf-or-xps")] public ActionResult CreatePDFOrXPS() { return View("create-pdf-or-xps", Orders); } [GridDataSourceAction] [ActionName("PagingGetData")] public ActionResult PagingGetData() { return View("create-pdf-or-xps", Orders); } [HttpPost] [ActionName("create-pdf-or-xps")] public void CreatePDFOrXPS(string pageFormat, string pageOrientation, string exportType, int pageSize, int pageNumber) { //make the currentPageNumber start from 1 pageNumber++; List<Order> newOrders = Orders.ToList(); bool exportAllPages = false; if (exportType == "currentPage") { newOrders = newOrders .Skip<Order>(pageSize * (pageNumber - 1)) .Take<Order>(pageSize) .Select(c => new Order { OrderID = c.OrderID, ContactName = c.ContactName, ShipAddress = c.ShipAddress, OrderDate = c.OrderDate }) .ToList(); } else { newOrders = newOrders .Select(c => new Order { OrderID = c.OrderID, ContactName = c.ContactName, ShipAddress = c.ShipAddress, OrderDate = c.OrderDate }) .ToList(); exportAllPages = true; } ExportHelper exporter = new ExportHelper(newOrders, pageOrientation, pageNumber, exportAllPages); Report igReport = exporter.Report(); SendForDownload(igReport, pageFormat); } private void SendForDownload(Report report, string pageFormat) { string documentFileNameRoot; FileFormat exportFileFormat; documentFileNameRoot = string.Format("Document.{0}", pageFormat.ToLower()); exportFileFormat = (pageFormat.ToLower() == "pdf") ? FileFormat.PDF : FileFormat.XPS; Response.Clear(); Response.AppendHeader("content-disposition", "attachment; filename=" + documentFileNameRoot); Response.ContentType = "application/octet-stream"; report.Publish(Response.OutputStream, exportFileFormat); Response.End(); } #region Report private class ExportHelper { #region Private private string Author = "インフラジスティックス・ジャパン株式会社"; private string Creator = "Infragistics Report Writer"; private string Copyright = string.Format("Copyright © 2003-{0} by Infragistics, Inc.", DateTime.Now.Year.ToString()); private Report report; // Report Section private static ISection section; // Styles private static Borders bordersStyle; private static Font fontStyle; private static Font headerFont; //Report options private List<Order> ordersData; private string pageOrientation; private int currentPageNumber; private bool exportAllPages; #endregion /// <summary> /// The ReportExporter creates an sample report based igGrid and the data source attached to it. /// </summary> /// <param name="data">A sample data.</param> /// <param name="pageOrientation">Landscape or Portrait.</param> /// <param name="currentPageNumber">The selected page in the grid. </param> public ExportHelper(List<Order> data, string pageOrientation, int currentPageNumber, bool exportAllPages) { this.ordersData = data; this.pageOrientation = pageOrientation; this.currentPageNumber = currentPageNumber; this.exportAllPages = exportAllPages; } /// <summary> /// Creates an report object with the passed data. /// </summary> /// <returns>Returns a Report object.</returns> public Report Report() { SetupStyles(); SetupReportInfo("ドキュメント エクスポーター"); IBand reportHeader = section.AddBand(); IText reportHeaderText = reportHeader.AddText(); reportHeaderText.Height = new FixedHeight(30); reportHeaderText.Style.Font = headerFont; if (this.exportAllPages) { reportHeaderText.AddContent("エクスポートが完了しました。レポートのすべてのページをエクスポートしました。"); } else { reportHeaderText.AddContent(string.Format("エクスポートが完了しました。ページ {0} をエクスポートしました。", this.currentPageNumber)); } ITable table = section.AddTable(); table.Borders = bordersStyle; table.Margins.Top = 5; table.Margins.Bottom = 5; table.Width = new RelativeWidth(100); table.Margins.Left = 30; // Header ITableHeader header = table.Header; header.Height = new FixedHeight(24); header.Repeat = true; this.AddHeaderCell(header, "注文 ID"); this.AddHeaderCell(header, "名前"); this.AddHeaderCell(header, "配送先住所"); this.AddHeaderCell(header, "注文日"); //Here we add all the rows of the table this.AddTableRows(table); return report; } private void AddHeaderCell(ITableHeader header, string text, Width width = null) { IText headerText; ITableCell cell = header.AddCell(); Color startColor = new Color(117, 117, 117); Color endColor = new Color(84, 84, 84); cell.Borders = bordersStyle; cell.Background = new Background(new LinearGradientBrush(startColor, endColor, 90)); cell.Alignment.Vertical = Alignment.Middle; if (width != null) { cell.Width = width; } headerText = cell.AddText(); headerText.Style.Font = headerFont; headerText.Style.Brush = Brushes.White; headerText.Alignment = TextAlignment.Center; headerText.AddContent(text); } private void AddTableRows(ITable table) { ITableRow tableRow; ITableCell tableCell; IText cellText; int i = 0; Paddings cellPaddings = new Paddings(3, 0, 5, 3); string modifiedDate; foreach (Order order in this.ordersData) { tableRow = table.AddRow(); tableRow.Height = new FixedHeight(30); Background cellBackgroundColor = (i % 2 == 0) ? new Background(Colors.White) : new Background(new Color(235, 235, 235)); tableCell = tableRow.AddCell(); tableCell.Paddings = cellPaddings; tableCell.Background = cellBackgroundColor; tableCell.Borders = bordersStyle; cellText = tableCell.AddText(); cellText.Style.Font = fontStyle; cellText.AddContent(order.OrderID.ToString()); tableCell = tableRow.AddCell(); tableCell.Paddings = cellPaddings; tableCell.Background = cellBackgroundColor; tableCell.Borders = bordersStyle; cellText = tableCell.AddText(); cellText.Style.Font = fontStyle; cellText.AddContent(order.ContactName.ToString()); tableCell = tableRow.AddCell(); tableCell.Paddings = cellPaddings; tableCell.Background = cellBackgroundColor; tableCell.Borders = bordersStyle; cellText = tableCell.AddText(); cellText.Style.Font = fontStyle; cellText.AddContent(order.ShipAddress.ToString()); tableCell = tableRow.AddCell(); tableCell.Paddings = cellPaddings; tableCell.Background = cellBackgroundColor; tableCell.Borders = bordersStyle; cellText = tableCell.AddText(); cellText.Style.Font = fontStyle; modifiedDate = order.OrderDate != null ? string.Format("{0:d}", order.OrderDate) : ""; cellText.AddContent(modifiedDate); i++; } } private void SetupReportInfo(string title) { report = new Report(); report.Info.Title = title; report.Info.Author = Author; report.Info.Creator = Creator; report.Info.Copyright = Copyright; report.Preferences.Printing.PaperSize = PaperSize.Auto; report.Preferences.Printing.PaperOrientation = PaperOrientation.Auto; report.Preferences.Printing.FitToMargins = true; SetupDefaultSection(); } private void SetupDefaultSection() { section = report.AddSection(); section.PageSize = PageSizes.Letter; section.PageMargins.All = 35; if (pageOrientation == "portrait") { section.PageOrientation = PageOrientation.Portrait; } else { section.PageOrientation = PageOrientation.Landscape; } } private void SetupStyles() { bordersStyle = new Borders(new Pen(new Color(117, 117, 117), (float)0.5, DashStyle.Solid)); fontStyle = new Font("Meiryo", 9); headerFont = new Font("Meiryo", 11, 0); } } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IgniteUI.SamplesBrowser.Models.Northwind { public class Order { public int OrderID { get; set; } public string CustomerID { get; set; } public Nullable<int> EmployeeID { get; set; } public Nullable<System.DateTime> OrderDate { get; set; } public Nullable<System.DateTime> RequiredDate { get; set; } public Nullable<System.DateTime> ShippedDate { get; set; } public Nullable<int> ShipVia { get; set; } public Nullable<decimal> Freight { get; set; } public string ShipName { get; set; } public string ShipAddress { get; set; } public string ShipCity { get; set; } public string ShipRegion { get; set; } public string ShipPostalCode { get; set; } public string ShipCountry { get; set; } public string ContactName { get; set; } public string EmployeeName { get; set; } public int ShipperID { get; set; } public string ShipperName { get; set; } public decimal TotalPrice { get; set; } public int TotalItems { get; set; } } }