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



The information in this article applies to:

  • Microsoft Office XP 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 "More Information" section of this article.

MORE INFORMATION

Steps to Reproduce the Problem

  1. In any HTML editor, create a new HTML file named CustomChart.htm, and paste the following code:
    <html>
    
    <body>
    <p align="center">
    <div>
    <object classid="clsid:0002E556-0000-0000-C000-000000000046" 
    id="WebChart" style="width:500px;height:300px">
    </object>
    <img id="ChartImg" style="display:none"/>
    </div>
    </p>
    </body>
    
    <script language="VBScript">
    
    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("Qtr1", "Qtr2", "Qtr3", "Qtr4")
        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 = "My Custom Chart Text"
        drawObject.Font.Size = 14
        drawObject.Font.Color = "green"
        drawObject.DrawText sText, _
             WebChart.Object.Right/2 - drawObject.TextWidth(sText)/2, _
             oChart.PlotArea.Bottom + 70
        
    End Function
    
    '=== Workaround ===
    '
    'Function Window_OnBeforePrint()
    '
    '    WebChart.ExportPicture "c:\chart.gif", "gif", 500, 300
    '    ChartImg.src = "c:\chart.gif"
    '    WebChart.style.display = "none"
    '    ChartImg.style.display = "inline" 
    ' 
    'End Function
    '
    'Function Window_OnAfterPrint()
    '
    '    ChartImg.style.display = "none"
    '    WebChart.style.display = "inline"
    '    
    'End Function
    
    </script>
    </html>
    					
  2. 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).
  3. From the File menu, click Print, and then click OK.
  4. 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.

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.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

286323 PRB: Data Bound Office XP Chart Prints Incorrectly From Internet Explorer 5.0

For more information about Microsoft Office and Office Web components, see the following Microsoft Web sites:

Microsoft Office Web Components Microsoft Office Developer Center

Modification Type:MinorLast Reviewed:8/23/2005
Keywords:kbOfficeWebChart kbprb KB291128