Microsoft KB Archive/291128

= PRB: Custom Layout and Drawings in Office XP Chart Do Not Print in Internet Explorer 5.0 =

Article ID: 291128

Article Last Modified on 8/23/2005

-

APPLIES TO


 * Microsoft Office Web Components

-



This article was previously published under Q291128



SYMPTOMS
When you print a Web page that contains an Office XP Chart component in Microsoft Internet Explorer, the layout customization and/or drawings for the ChartSpace are not reflected in the printed output.



CAUSE
When you print a Web page from Internet Explorer 5, Internet Explorer requests that controls on the page persist their information, and a copy of the Web page is stored to the Temp folder. Then, Internet Explorer shells a new process, which loads the persisted page for printing. When the persisted page is loaded, the script is not run. Therefore, because layout and render events are not run when the persisted page is printed, the printed output does not reflect the customization that is handled in those events.



RESOLUTION
To work around this problem, use one of the following methods:  Upgrade to Internet Explorer 5.5. This problem does not occur in Internet Explorer 5.5 because the printing facilities changed. Use server-side code with the Chart component to create non-interactive charts (images) using the GetPicture method for the ChartSpace object.For additional information and for sample code that demonstrates this workaround, click the article number below to view the article in the Microsoft Knowledge Base:

286277 HOWTO: Use the Office XP Chart Component to Create Static Charts with ASP

 For printing purposes, use client-side code with the ExportPicture method of the ChartSpace object to create a chart image from an interactive chart. This workaround is demonstrated in the &quot;More Information&quot; section of this article.



Steps to Reproduce the Problem
  In any HTML editor, create a new HTML file named CustomChart.htm, and paste the following code:

 <object classid=&quot;clsid:0002E556-0000-0000-C000-000000000046&quot; id=&quot;WebChart&quot; style=&quot;width:500px;height:300px&quot;> <img id=&quot;ChartImg&quot; style=&quot;display:none&quot;/>

<script language=&quot;VBScript&quot;>

Dim oChart, oSeries, c

Function Window_OnLoad

Set c = WebChart.Constants 'Use literal data to create a column chart with one series. WebChart.Clear Set oChart = WebChart.Charts.Add Set oSeries = oChart.SeriesCollection.Add oSeries.SetData c.chDimCategories, c.chDataLiteral, _ Array(&quot;Qtr1&quot;, &quot;Qtr2&quot;, &quot;Qtr3&quot;, &quot;Qtr4&quot;) oSeries.SetData c.chDimValues, c.chDataLiteral, _ Array(100500, 152530, 95150, 13265) 'Allow Render events to get a handle on the ChChartDraw object so that 'custom lines, shapes, and text can be drawn on the chart. WebChart.AllowRenderEvents = True 'Allow layout events so that the chart's plot area can be repositioned 'and resized. WebChart.AllowLayoutEvents = True

End Function

Function WebChart_AfterLayout(drawObject)

'Resize the chart's plot area to provide room at the bottom 'of the chart space for custom drawn text. oChart.PlotArea.Bottom = oChart.PlotArea.Bottom - 140 End Function

Function WebChart_AfterFinalRender(drawObject)

'Add custom text beneath the plot area. sText = &quot;My Custom Chart Text&quot; drawObject.Font.Size = 14 drawObject.Font.Color = &quot;green&quot; drawObject.DrawText sText, _ WebChart.Object.Right/2 - drawObject.TextWidth(sText)/2, _ oChart.PlotArea.Bottom + 70 End Function

'=== Workaround === ' 'Function Window_OnBeforePrint ' '   WebChart.ExportPicture &quot;c:\chart.gif&quot;, &quot;gif&quot;, 500, 300 '   ChartImg.src = &quot;c:\chart.gif&quot; '   WebChart.style.display = &quot;none&quot; '   ChartImg.style.display = &quot;inline&quot; ' 'End Function ' 'Function Window_OnAfterPrint ' '   ChartImg.style.display = &quot;none&quot; '   WebChart.style.display = &quot;inline&quot; '   'End Function

</li> Start Internet Explorer, and browse to CustomChart.htm. A chart is rendered on a Web page; the chart has a custom layout (the plot area is sized) and a drawing (text beneath the plot area).</li> From the File menu, click Print, and then click OK.</li> Examine the printed output.

In Internet Explorer 5, the printed output does not match the chart as it appears on the Web page. The output contains the chart but does not contain the drawing and does not reflect the custom layout.

In Internet Explorer 5.5, the printed output matches the chart as it appears on the Web page.</li></ol>

Workaround
To test the workaround that uses ExportPicture to create an image for printing purposes, follow these steps:
 * 1) Uncomment the code for the OnBeforePrint and OnAfterPrint events in the preceding script, and save the file.
 * 2) In Internet Explorer, refresh CustomChart.htm.
 * 3) From the File menu, click Print, and then click OK.
 * 4) When you are prompted to confirm the creation of c:\chart.gif, click Yes. The chart in the printed output now reflects the custom layout and drawings.

Note You cannot avoid the prompt when you use ExportPicture to save a file from client-side script. If you do not want the user to be presented with this prompt, use server-side script when you export the chart to an image.

<div class="references_section">