<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>All I don&#039;t know &#187; Print</title>
	<atom:link href="http://blog.derraab.com/tag/print/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.derraab.com</link>
	<description>About Flash™, Flex™, software development and my computer. And JavaScript.</description>
	<lastBuildDate>Sat, 26 Nov 2011 18:31:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>No flash events after PrintJob.start()</title>
		<link>http://blog.derraab.com/2008/11/06/no-flash-events-after-printjobstart/</link>
		<comments>http://blog.derraab.com/2008/11/06/no-flash-events-after-printjobstart/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 12:54:39 +0000</pubDate>
		<dc:creator>derRaab</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash in Browser]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Print]]></category>
		<category><![CDATA[PrintJob]]></category>

		<guid isPermaLink="false">http://blog.derraab.com/?p=57</guid>
		<description><![CDATA[While developing the print functionality within a framework I got stuck on the behaviour of the Flash Player print implementation. I couldn&#8217;t solve the following steps: Start the PrintJob and display the print dialog Procceed the following tasks for every &#8230; <a href="http://blog.derraab.com/2008/11/06/no-flash-events-after-printjobstart/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While developing the print functionality within a framework I got stuck on the behaviour of the Flash Player print implementation.</p>
<p>I couldn&#8217;t solve the following steps:</p>
<ol>
<li>Start the PrintJob and display the print dialog</li>
<li>Procceed the following tasks for every print page:
<ul>
<li>Load dynamic data into view templates (images, text, video&#8230;)</li>
<li>Wait for the onLoadComplete event and add the displayed contents using PrintJob.addPage()</li>
<li>Repeat for next page&#8230;</li>
</ul>
</li>
<li>Call PrintJob.send()</li>
</ol>
<p>I really thought this would be an easy task but now I think it&#8217;s not possible. Several attempts later I figured out that after calling PrintJob.start() there is no way to use the flash event model! This means loading contents after calling PrintJob.start() is impossible!</p>
<p>WOW!</p>
<p>So I used a workaround: I create all the print pages like I mentioned before, but without calls on the PrintJob-API. I simply store every print page as BitmapData and afterwards I create the PrintJob within a loop.</p>
<p>Now I have multiple other problems:</p>
<ul>
<li>Hundreds of pages use a huge amount of RAM and often crash the application.</li>
<li>The bitmap resolution sucks so printout text quality is unsatisfying and due to point 1 I have no chance to work with higher quality.</li>
<li>I must avoid skript timeouts because after preparing all the bitmaps it takes much more that 15 seconds to add all these pages to a PrintJob.</li>
</ul>
<p>Did I slip something?</p>
<p>Finally I created a small example to show you the disfunctionality (<a href='http://blog.derraab.com/wp-content/uploads/2008/11/printjobproblem.as'>PrintJobProblem.as</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package  
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Rectangle</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">printing</span>.<span style="color: #0066CC;">PrintJob</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">TextFieldAutoSize</span>;
    <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #0066CC;">getTimer</span>;    
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @author Markus Raab - derRaab.com / superclass.de
     */</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PrintJobProblem <span style="color: #0066CC;">extends</span> Sprite 
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _numPrintOuts : <span style="color: #0066CC;">int</span>;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _printOutIndex : <span style="color: #0066CC;">int</span>;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _printJob : <span style="color: #0066CC;">PrintJob</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         * Starts a event based printout test after a loop based
         * test has successfully finished.
         */</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PrintJobProblem<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
            _numPrintOuts = <span style="color: #cc66cc;">2</span>;
&nbsp;
            runLoopBasedTest<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>;
            runEventBasedTest<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         * Demonstrates and ensures the functionality.
         */</span>
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> runLoopBasedTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            _printJob = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">PrintJob</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _printJob.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>    
                <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> _numPrintOuts; i++ <span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #0066CC;">addPage</span><span style="color: #66cc66;">&#40;</span> i <span style="color: #66cc66;">&#41;</span>;
                <span style="color: #66cc66;">&#125;</span>
&nbsp;
                _printJob.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/**
         * Demonstrates that after calling PrintJob.start() the internal
         * eventmodel doesn't dispatch any events at all. Everything is blocked
         * until the script times out.
         */</span>
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> runEventBasedTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            _printJob = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">PrintJob</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _printJob.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;PrintJob.start() called&quot;</span> <span style="color: #66cc66;">&#41;</span>;
                _printOutIndex = <span style="color: #cc66cc;">0</span>;
&nbsp;
                startAddPagesOnEnterFrame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> startAddPagesOnEnterFrame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            addEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span>, onAddPagesOnEnterFrameEvent <span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onAddPagesOnEnterFrameEvent<span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _printOutIndex == _numPrintOuts <span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                stopAddPagesOnEnterFrame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
                _printJob.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;PrintJob.send()&quot;</span> <span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #b1b100;">else</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #0066CC;">addPage</span><span style="color: #66cc66;">&#40;</span> _printOutIndex++ <span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> stopAddPagesOnEnterFrame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            removeEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span>, onAddPagesOnEnterFrameEvent <span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">addPage</span><span style="color: #66cc66;">&#40;</span> pageIndex : <span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> page : Sprite = createPrintPage<span style="color: #66cc66;">&#40;</span> pageIndex <span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> page <span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #000000; font-weight: bold;">var</span> viewWidth : <span style="color: #0066CC;">Number</span> = page.<span style="color: #0066CC;">width</span>;
            <span style="color: #000000; font-weight: bold;">var</span> viewHeight : <span style="color: #0066CC;">Number</span> = page.<span style="color: #0066CC;">height</span>;
&nbsp;
            <span style="color: #000000; font-weight: bold;">var</span> scaleX : <span style="color: #0066CC;">Number</span> = _printJob.<span style="color: #006600;">pageWidth</span> <span style="color: #66cc66;">/</span> viewWidth;
            <span style="color: #000000; font-weight: bold;">var</span> scaleY : <span style="color: #0066CC;">Number</span> = _printJob.<span style="color: #006600;">pageHeight</span> <span style="color: #66cc66;">/</span> viewHeight;
            <span style="color: #000000; font-weight: bold;">var</span> scale : <span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span> scaleX, scaleY <span style="color: #66cc66;">&#41;</span>;
&nbsp;
            page.<span style="color: #006600;">scaleX</span> = page.<span style="color: #006600;">scaleY</span> = scale;
&nbsp;
            <span style="color: #000000; font-weight: bold;">var</span> printRect : Rectangle = <span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, viewWidth, viewHeight <span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #0066CC;">try</span>
            <span style="color: #66cc66;">&#123;</span>
                _printJob.<span style="color: #0066CC;">addPage</span><span style="color: #66cc66;">&#40;</span> page, printRect <span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>: <span style="color: #0066CC;">Error</span> <span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">getTimer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;PrintJob.addPage() failed&quot;</span> <span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span> page <span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createPrintPage<span style="color: #66cc66;">&#40;</span> pageIndex : <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span> : Sprite
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> page : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">textField</span> : <span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #0066CC;">textField</span>.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;
                <span style="color: #0066CC;">textField</span>.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Page &quot;</span> + pageIndex;
&nbsp;
            page.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">textField</span> <span style="color: #66cc66;">&#41;</span>;    
&nbsp;
            <span style="color: #b1b100;">return</span> page;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.derraab.com/2008/11/06/no-flash-events-after-printjobstart/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

