问题描述
我的数据网格打印从页面的顶部开始。我无法弄清楚如何移动数据网格。我没有看到FlexPrintJob或PrintAdvancedDataGrid中的任何内容。我必须创建一个空白对象来添加到我的FlexPrintJob对象的顶部?任何帮助或链接,将有所帮助。
谢谢,
John
在尝试了很多示例adobe和其他一些对我没有任何作用的示例之后,我发现我不得不将数据网格放在一个vBox中,我可以在数据网格上面放一个空头。正如所有的例子所显示的,这是最好的一个vBox组件。
下面是我想到的一个工作示例,与我发现的示例有点不同。在vBox组件中,您可以做很多事情来增强打印作业。在我的情况下,我添加了一个标题和日期。
希望这可以帮助那里的人,
John
我正在使用泛型函数来打印任何AdvancedDataGrid,我可能在我的应用程序中...
pre ()函数返回一个新的数组元素,其中包含一个元素,这个元素包含一个元素,一个元素,一个元素,一个元素,一个元素,一个元素,一个元素,一个元素。
if(printJob.start()){
//创建包含datagrid的FormPrintView_ADG组件实例
var thePrintView:FormPrintView_ADG = new FormPrintView_ADG();
//将组件添加到我的应用程序
FlexGlobals.topLevelApplication.addChild(thePrintView);
//载入数据网格
thePrintView.printDataGrid.dataProvider = xmlListCollection.copy();
//格式化数据网格
thePrintView.printDataGrid.width = printJob.pageWidth-45; //在右对齐的vBox中设置dg的左边距
thePrintView.printDataGrid.height = printJob.pageHeight-73; //页眉标题和日期调整
thePrintView.printDataGrid.setStyle(fontSize,8);
thePrintView.printDataGrid.columns = advDG.columns;
thePrintView.printDataGrid.setStyle(fontFamily,Times);
thePrintView.printDataGrid.setStyle(color,000000);
//设置标题文本
thePrintView.headerText.height = 45;
thePrintView.headerText.width = printJob.pageWidth-20;
thePrintView.headerText.text =\r+ headerText;
//将第一页添加到打印作业
printJob.addObject(thePrintView,FlexPrintJobScaleType.NONE);
while(thePrintView.printDataGrid.validNextPage){
//将下一页的数据移动到PrintDataGrid的顶部,并将其添加到printjob
thePrintView.printDataGrid.nextPage();
printJob.addObject(thePrintView,FlexPrintJobScaleType.NONE);
}
//打印并从我的应用程序中删除组件
printJob.send();
FlexGlobals.topLevelApplication.removeChild(thePrintView);
这是我使用的vBox组件...
<?xml version =1.0?>
horizontalAlign =right
creationComplete =init();> ;
< mx:Script>
<![CDATA [
[Bindable] private var date:String;
private function init():void {
date = new Date()。toString();
date = df.format(date);
}
]]>
< / mx:Script>
< mx:DateFormatter id =dfformatString =EEEE,MMMM D,YYYY/>
< mx:TextArea id =headerTextborderThickness =0color =#000000fontWeight =bold
textAlign =centertextDecoration =none/>
< mx:PrintAdvancedDataGrid id =printDataGrid/>
< / mx:VBox>
My datagrid prints starting at the very top of the page. I can't figure out how to move the datagrid down. I don't see anything in FlexPrintJob or PrintAdvancedDataGrid that will do this. Do I have to create a blank object to add to the top of my FlexPrintJob object?
Any help or a link that will help.
Thanks,
John
After trying a lot of examples form adobe and others that did not work at all for me, I figured out that I had to put the datagrid in a vBox where I could put a blank header above the datagrid. As all of the examples showed, this was best done with a vBox component.
Below is a working example of what I came up with, which is a bit different than the examples I found. In the vBox component you can do a lot of things to enhance the print job. In my case I added a title and date.
Hope this helps someone out there,
John
I am tusing a generic function to print any AdvancedDataGrid I might have in my application...
public function printAdvancedDataGridContents(advDG:AdvancedDataGrid, xmlListCollection:XMLListCollection, headerText:String):void
{
const printJob:FlexPrintJob = new FlexPrintJob();
if ( printJob.start() ) {
//create an instance of the FormPrintView_ADG component containing the datagrid
var thePrintView:FormPrintView_ADG = new FormPrintView_ADG();
//add the component to my application
FlexGlobals.topLevelApplication.addChild(thePrintView);
//load the datagrid
thePrintView.printDataGrid.dataProvider = xmlListCollection.copy();
//format the datagrid
thePrintView.printDataGrid.width = printJob.pageWidth-45; //set a left margin for the dg in a right justiified vBox
thePrintView.printDataGrid.height = printJob.pageHeight-73; //page adjusted for header title and date
thePrintView.printDataGrid.setStyle("fontSize", 8);
thePrintView.printDataGrid.columns = advDG.columns;
thePrintView.printDataGrid.setStyle("fontFamily", 'Times');
thePrintView.printDataGrid.setStyle("color", 000000);
//set the header text
thePrintView.headerText.height = 45;
thePrintView.headerText.width = printJob.pageWidth-20;
thePrintView.headerText.text = "\r"+headerText;
//add the first page to the print job
printJob.addObject(thePrintView, FlexPrintJobScaleType.NONE);
while (thePrintView.printDataGrid.validNextPage) {
// Move the next page of data to the top of the PrintDataGrid and add it to the printjob
thePrintView.printDataGrid.nextPage();
printJob.addObject(thePrintView, FlexPrintJobScaleType.NONE);
}
//print it and remove the component from my application
printJob.send();
FlexGlobals.topLevelApplication.removeChild(thePrintView);
}
}
Here is the vBox component I am using...
<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="right"
creationComplete="init();">
<mx:Script>
<![CDATA[
[Bindable] private var date:String;
private function init():void{
date = new Date().toString();
date = df.format(date);
}
]]>
</mx:Script>
<mx:DateFormatter id="df" formatString="EEEE, MMMM D, YYYY"/>
<!-- this header can contain a title or be left blank to create a top margin -->
<mx:TextArea id="headerText" borderThickness="0" color="#000000" fontWeight="bold"
textAlign="center" textDecoration="none"/>
<!-- date label. set visible to false in the calling function if not needed -->
<mx:Label color="#000000" fontSize="8" fontStyle="normal" fontWeight="normal" text="{date}"/>
<!-- the data grid -->
<mx:PrintAdvancedDataGrid id="printDataGrid"/>
</mx:VBox>
这篇关于如何在打印PrintAdvancedDataGrid时创建顶部边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!