热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Printingmultipageoutput

Printingknown-lengthmultipageoutputUsingthePrintDataGridcontrolformultipagegridsExample:Pr

You can print well-formatted multipage output under the following conditions:

  • When each control fits on a print page or less. You often encounter such jobs when printing a form with fixed-length fields.

  • When the printed output includes one or more PrintDataGrid controls that are too long to print on a single page, particularly if the control height might vary, depending on the data. A good example of this type of output is a customer order receipt, which starts with the customer information, has an indeterminate number of order line items, and ends with total information.

Printing known-length multipage output

If you know the length of each component in a multipage document, you can create a separate print layout component for each page you print, and specify each layout page in a separateaddObject()method, as follows:

printJob.addObject(introPrintView, "ShowAll"); 
printJob.addObject(finDetailPrintView, "ShowAll"); 
printJob.addObject(hrDetailPrintView, "ShowAll"); 
printJob.addObject(summaryPrintView, "ShowAll");

Using the PrintDataGrid control for multipage grids

When a DataGrid control with many rows does not fit on a single screen in your application, you typically have scroll bars that let users view all the data. When you print the DataGrid control, the output is the same as the screen display. Therefore, if your DataGrid control has rows or columns that are not immediately visible, they do not print. If you replace the DataGrid control with a PrintDataGrid control that does not have a height specified (or has a large height), you print all the rows, but some rows could be partially printed on the bottom of one page and partially printed at the top of another, as you often see with HTML printout.

You can solve these problems by using the following features of the PrintDataGrid control. These features let you correctly print grids that contain multiple pages of data without splitting rows across pages:

sizeToPage property
Makes the printed data grid contain only full rows.

 

nextPage() method
Gets the next printable page of data.

 

validNextPage property
Istrueif printing the data requires an additional page.

 

Using the sizeToPage attribute to format pages

A PrintDataGrid page consists of the rows that are visible in the control’s current view. Suppose, for example, that a PrintDataGrid control has a height of 130 pixels. The total height of each row and header is 30 pixels, and the control’s data provider has 10 rows. In this situation, the printed PrintDataGrid page contains only three complete data rows, plus the header. ThesizeToPageproperty specifies whether to include a fourth and partial data row.

ThesizeToPageproperty, which istrueby default, causes the PrintDataGrid control to remove any partially visible or empty rows and to resize itself to include only complete rows in the current view. For the data grid described in the preceding paragraph, when this property istrue, the DataGrid shrinks to show three complete data rows, and no incomplete rows; if the attribute isfalse, the grid includes a partial row at the bottom.

The following properties provide information on page sizing that are affected by thesizeToPageproperty:

Property

Description

currentPageHeight

Contains the height of the grid, in pixels, that results if thesizeToPageproperty istrue. If thesizeToPageproperty istrue, thecurrentPageHeightproperty equals theheightproperty.

originalHeight

Contains the grid height that results if thesizeToPageproperty isfalse. If thesizeToPageproperty isfalse, theoriginalHeightproperty equals theheightproperty.

In most applications, you leave thesizeToPageattribute at its default value (true), and use theheightproperty to determine the grid height.

ThesizeToPageproperty does not affect the way the page breaks when a single PrintDataGrid control page is longer than a print page. To print multipage data grids without splitting rows, you must divide the grid items into multiple views by using thenextPage()method, as described in the following section.

Using the nextPage() method and validNextPage property to print multiple pages

ThevalidNextPageproperty istrueif the PrintDataGrid control has data beyond the rows that fit on the current print page. You use it to determine whether you need to format and print an additional page.

ThenextPage()method lets you page through the data provider contents by setting the first row of the PrintDataGrid control to be the data provider row that follows the last row of the previous PrintDataGrid page. In other words, thenextPage()method increases the grid’sverticalScrollPositionproperty by the value of the grid’srowCountproperty.

The following code shows a loop that prints a grid using multiple pages, without having rows that span pages:

// Queue the first page. 
printJob.addObject(thePrintView); 
// While there are more pages, print them. 
while (thePrintView.myDataGrid.validNextPage) { 
    //Put the next page of data in the view. 
    thePrintView.myDataGrid.nextPage(); 
    //Queue the additional page. 
    printJob.addObject(thePrintView); 
}

The section Example: Printing with multipage PrintDataGrid controls shows how to use thenextPage()method to print a report with a multipage data grid.

Updating the PrintDataGrid layout

When you use a PrintDataGrid control to print a single data grid across multiple pages, you queue each page of the grid individually. If your application customizes each page beyond simply using thenextPage()method to page through the PrintDataGrid, you must call thevalidateNow()method to update the page layout before you print each page, as shown in Print output component.

Example: Printing with multipage PrintDataGrid controls

The following example prints a data grid in which you can specify the number of items in the data provider. You can, therefore, set the DataGrid control contents to print on one, two, or more pages, so that you can see the effects of different-sized data sets on the printed result.

The example also shows how you can put header information before the grid and footer information after the grid, as in a shipping list or receipt. It uses the technique of selectively showing and hiding the header and footer, depending on the page being printed. To keep the code as short as possible, the example uses simple placeholder information only.

The application consists of the following files:

  • The application file displays the form to the user, including TextArea and Button controls to set the number of lines and a Print button. The file includes the code to initialize the view, get the data, and handle the user’s print request. It uses the FormPrintView MXML component as a template for the printed output.

  • The FormPrintView.mxml file formats the printed output. It has two major elements:

    • The print output template includes the PrintDataGrid control and uses two MXML components to format the header and footer contents.

    • TheshowPage()function determines which sections of the template to include in a particular page of the output, based on the page type: first, middle, last, or single. On the first page of multipage output, theshowPage()function hides the footer; on the middle and last pages, it hides the header. On a single page, it shows both header and footer.

  • The FormPrintHeader.mxml and formPrintFooter.mxml files specify the contents of the start and the end of the output. To keep the application simple, the header has a single, static Label control. The footer displays a total of the numbers in the Quantity column. In a more complete application, the header page could have, for example, a shipping address, and the footer page could show more detail about the shipment totals.

The files include detailed comments explaining the purpose of the code.

Multipage print application file

The following code shows the multipage print application file:





    
    
    

    
    
        
                
                
                    
                    
                
            
        
        
        
            
            
        
    

The executing SWF file for the previous example is shown below:

 

Print output component

The following lines show the FormPrintView.mxml custom component file:





    
        
    

    
    
        
    
    
    
    
    
    
        
            
            
        
    
    
    
    

Header and footer files

The following lines show the FormPrintHeader.mxml file.





    

The following lines show the FormPrintFooter.mxml file:




    
    
    
        
        

    

Using the PrintAdvancedDataGrid control

The PrintAdvancedDataGrid and PrintOLAPDataGridcontrols provide the same functionality for the AdvancedDataGrid and OLAPDataGrid controls as the PrintDataGrid control does for the DataGrid control. For more information, see Using the PrintDataGrid control for multipage grids.

The following example uses the PrintAdvancedDataGrid control to print an instance of the AdvancedDataGrid control.




 
    
        
    

    
        
            
                
            
            
                
                
                
                
            
            

        
        

The executing SWF file for the previous example is shown below:

 
The contents of the included SimpleHierarchicalData.as file are as follows:
[Bindable]
private var dpHierarchy:ArrayCollection = new ArrayCollection([
  {Region:"Southwest", children: [
     {Region:"Arizona", children: [ 
        {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000}, 
        {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]},  
     {Region:"Central California", children: [ 
        {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]},  
     {Region:"Nevada", children: [ 
        {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]},  
     {Region:"Northern California", children: [ 
        {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000}, 
        {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]},  
     {Region:"Southern California", children: [ 
        {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000}, 
        {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}]}
  ]}
]);

This example uses thePrintAdvancedDataGrid.sourceproperty to initialize the PrintAdvancedDataGrid control from the AdvancedDataGrid control.

To support the AdvancedDataGrid control, the PrintAdvancedDataGrid control adds the following properties not available in the PrintDataGrid control:

Property

Description

allowInteractions

Iftrue, allow some interactions with the control, such as column resizing, column reordering, and expanding or collapsing nodes. The default value isfalse.

displayIcons

Iftrue, display the folder and leaf icons in the navigation tree. The default value istrue.

source

Initialize the PrintAdvancedDataGrid control and all of its properties from the specified AdvancedDataGrid control.

validPreviousPage

Indicates that the data provider contains data rows that precede the rows that the PrintAdvancedDataGrid control currently displays.

 

Printing multipage output,,

Printing multipage output


推荐阅读
  • 阿里云 Aliplayer高级功能介绍(八):安全播放
    如何保障视频内容的安全,不被盗链、非法下载和传播,阿里云视频点播已经有一套完善的机 ... [详细]
  • 本文详细介绍了Linux系统中用于管理IPC(Inter-Process Communication)资源的两个重要命令:ipcs和ipcrm。通过这些命令,用户可以查看和删除系统中的消息队列、共享内存和信号量。 ... [详细]
  • 从零开始编译Linux系统:第16章 全新起点
    本章将详细介绍如何从零开始编译一套完整的Linux系统,涵盖关键组件如glibc库的介绍及其重要性。通过本文,读者将了解从源代码构建Linux系统的全过程。 ... [详细]
  • SvpplyTable: 实现可扩展和可折叠的菜单动画
    SvpplyTable 是一个示例项目,旨在实现类似 Svpply 应用程序中的可扩展和可折叠的菜单动画效果。该项目托管在 GitHub 上,地址为 https://github.com/liuminqian/SvpplyTable。 ... [详细]
  • 本文介绍了如何使用Postman构建和发送HTTP请求,包括四个主要部分:方法(Method)、URL、头部(Headers)和主体(Body)。特别强调了Body部分的重要性,并详细说明了不同类型的请求体。 ... [详细]
  • iOS snow animation
    CTSnowAnimationView.hCTMyCtripCreatedbyalexon1614.Copyright©2016年ctrip.Allrightsreserved.# ... [详细]
  • packagecom.panchan.tsmese.utils;importjava.lang.reflect.ParameterizedType;importjava.lang. ... [详细]
  • 经过一年的思考,我发现自己对开发的兴趣并不浓厚,而对算法研究则更加热衷。本文将探讨开发与算法之间的本质差异,并分享我的未来学习计划。 ... [详细]
  • 年前,我发表了一篇文章,分享了自己通过在线教育平台学习IT技能的经历。文中详细探讨了在线教育与传统线下教育在技能培训方面的优缺点。许多网友在讨论在线教育时,常常提到“在线教育是否缺乏学习氛围”的问题。本文将对此进行深入分析。 ... [详细]
  • JavaSE For循环入门示例
    本文将介绍Java中For循环的基本概念和使用方法,通过几个简单的示例帮助初学者更好地理解和掌握For循环。 ... [详细]
  • 本文介绍了一种支付平台异步风控系统的架构模型,旨在为开发类似系统的工程师提供参考。 ... [详细]
  • Manacher算法详解:寻找最长回文子串
    本文将详细介绍Manacher算法,该算法用于高效地找到字符串中的最长回文子串。通过在字符间插入特殊符号,Manacher算法能够同时处理奇数和偶数长度的回文子串问题。 ... [详细]
  • malloc 是 C 语言中的一个标准库函数,全称为 memory allocation,即动态内存分配。它用于在程序运行时申请一块指定大小的连续内存区域,并返回该区域的起始地址。当无法预先确定内存的具体位置时,可以通过 malloc 动态分配内存。 ... [详细]
  • 本文介绍了多种开源数据库及其核心数据结构和算法,包括MySQL的B+树、MVCC和WAL,MongoDB的tokuDB和cola,boltDB的追加仅树和mmap,levelDB的LSM树,以及内存缓存中的一致性哈希。 ... [详细]
  • Python多线程详解与示例
    本文介绍了Python中的多线程编程,包括僵尸进程和孤儿进程的概念,并提供了具体的代码示例。同时,详细解释了0号进程和1号进程在系统中的作用。 ... [详细]
author-avatar
newphper
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有