我有几个在 Flex 中创建的图表组件。基本上,我设置了一个特殊的 UI,允许用户选择他们想要打印的图表。当他们按下打印按钮时,每个选定的图表都会动态创建,然后添加到容器中。然后我将此容器发送到 FlexPrintJob。
即
private function prePrint():void
{
var printSelection:Box = new Box();
printSelection.percentHeight = 100;
printSelection.percentWidth = 100;
printSelection.visible = true;
if (this.chkMyChart1.selected)
{
var rptMyChart1:Chart1Panel = new Chart1Panel();
rptMyChart1.percentHeight = 100;
rptMyChart1.percentWidth = 100;
rptMyChart1.visible = true;
printSelection.addChild(rptMyChart1);
}
print(printSelection);
}
private function print(container:Box):void
{
var job:FlexPrintJob;
job = new FlexPrintJob();
if (job.start()) {
job.addObject(container, FlexPrintJobScaleType.MATCH_WIDTH);
job.send();
}
}
,如果图表实际显示在页面上的某个位置,则此代码可以正常工作,但如上所示动态添加它则不然。将出现打印对话框,但当我按“确定”时什么也没有发生。
所以我真的有两个问题:
- 当柔性组件/图表在屏幕上不可见时,是否可以打印它们?
- 如果是这样,我该怎么做/我做错了什么?
更新:
嗯,至少有一件事是错误的,那就是我对宽度和高度百分比的使用。当 Box 不包含在另一个对象中时,使用百分比实际上没有意义。将高度和宽度更改为固定值实际上可以使打印继续进行并解决我最初的问题。
printSelection.height = 100;
printSelection.width = 100;
但出现了一个新问题,我看到的不是我的图表,而是一个黑匣子。我之前已经通过将图表的背景颜色设置为 #FFFFFF 解决了这个问题,但这一次似乎不起作用。
更新2:
我在adobe网站上看到了一些将容器添加到应用程序但不将其包含在布局中的示例。这看起来像是要走的路。
IE
printSelection.includeInLayout = false;
addChild(printSelection);
I have a several chart components that I have created in Flex. Basically I have set up a special UI that allows the user to select which of these charts they want to print. When they press the print button each of the selected charts is created dynamically then added to a container. Then I send this container off to FlexPrintJob.
i.e.
private function prePrint():void
{
var printSelection:Box = new Box();
printSelection.percentHeight = 100;
printSelection.percentWidth = 100;
printSelection.visible = true;
if (this.chkMyChart1.selected)
{
var rptMyChart1:Chart1Panel = new Chart1Panel();
rptMyChart1.percentHeight = 100;
rptMyChart1.percentWidth = 100;
rptMyChart1.visible = true;
printSelection.addChild(rptMyChart1);
}
print(printSelection);
}
private function print(container:Box):void
{
var job:FlexPrintJob;
job = new FlexPrintJob();
if (job.start()) {
job.addObject(container, FlexPrintJobScaleType.MATCH_WIDTH);
job.send();
}
}
This code works fine if the chart is actually displayed somewhere on the page but adding it dynamically as shown above does not. The print dialog will appear but nothing happens when I press OK.
So I really have two questions:
- Is it possible to print flex components/charts when they are not visible on the screen?
- If so, how do I do it / what am I doing wrong?
UPDATE:
Well, at least one thing wrong is my use of the percentages in the width and height. Using percentages doesn't really make sense when the Box is not contained in another object. Changing the height and width to fixed values actually allows the printing to progress and solves my initial problem.
printSelection.height = 100;
printSelection.width = 100;
But a new problem arises in that instead of seeing my chart, I see a black box instead. I have previously resolved this issue by setting the background colour of the chart to #FFFFFF but this doesn't seem to be working this time.
UPDATE 2:
I have seen some examples on the adobe site that add the container to the application but don't include it in the layout. This looks like the way to go.
i.e.
printSelection.includeInLayout = false;
addChild(printSelection);
发布评论
评论(2)
您的组件必须位于舞台上才能绘制其内容,因此您应该尝试如下操作:
...
然后进行打印
Your component has to be on the stage in order to draw its contents, so you should try something like this:
...
then do the printing
我不完全确定,但在我的一个应用程序中,我必须打印出完整的选项卡导航器,我发现打印它的唯一方法是自动滚动选项卡导航器选项卡,以便在我添加时在屏幕上显示组件他们到打印作业。
这样就全部打印出来了。在我创建 tabnaviagotr 滚动打印(到 PDF)之前,结果是一个包含选项卡所有页面的文件,但只有屏幕上可见的页面真正打印。
i'm not completely sure, but in one of my application I have to print out a complete Tab Navigator and the only method i have found to print it is to automatically scroll the tabnavigator tab in order to show the component on screen when i add them to the printjob.
In this way they are all printed. Before i created the tabnaviagotr scrolling the print (to PDF) result was a file with all the pages of the tab but only the one visible on screen really printed.