Printer friendly charts

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
nitin
Newbie
Newbie
Posts: 51
Joined: Thu Aug 22, 2002 4:00 am

Printer friendly charts

Post by nitin » Wed Apr 11, 2007 8:00 am

Hello!

I have a chart with many series in different colors. Everything looks fine on the screen but the quality is not good when I print the chart (especially on black and white printers). Any recommandations as to what can be done to improve on this?

I use Rave reports and TChart.SaveToMetafileEnh from Delphi 7.

Regards,
Erik

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Apr 11, 2007 8:40 am

Hi Erik,

Could you please read the article below about enhancing printing with TeeChart? If this doesn't help please let us know.

Thanks in advance.

Printing better.
----------------

This document explains how TeeChart components are printed, and describes how to improve printing.

1- Introduction
2- Design issues
3- How to Print Proportionally?
4- Other problems
5- Printing Reference
6- More information


1- Introduction
----------------

The TeeChart library is sending Charts to the printer using a Windows graphic format known as "metafile".

This format has several advantages and disadvantages over using the bitmap format:

- It's much smaller, because graphic information is stored in vector instructions, instead of pixels. This results in a faster printing speed in most cases. Also, the printer doesn't need to have more memory.

- Due to be a sequence of instructions instead of a fixed array of pixels, a metafile can be resized ( or "stretched" ) without loosing resolution, and with greater accuracy.

- New printers support metafile format natively, via software driver or via "gdi hardware".

With Windows 32-bit (Windows 95 and Windows NT), an extended metafile format is implemented. This is known as "enhanced metafile". Metafiles have the extension: "*.wmf" and enhanced metafiles: "*.emf".


2- Design issues
-----------------

The main goal of using metafiles in TeeChart, is to provide "wysiwyg" (what you see is what you get). That is, printed charts should look as close as possible to how they look at screen.

To do this, TeeChart creates a metafile of the Chart image, and then sends this metafile to the printer.

At this point, the Windows GDI module and the Windows Printer driver will take care of "painting" the Chart image on paper.

This involves "stretching" or "resizing" the metafile, from screen coordinates to printer logical pixels.

Example:
A Chart on screen is at rectangle:
Left : 100
Top : 100
Right : 300
Bottom: 400

And it gets printed at this paper rectangle:
Left : 400
Top : 1000
Right : 1200
Bottom: 1500

In this example, the Chart should be rescaled both in width and height:

screen Width = 300 - 100 = 200
paper Width = 1200 - 400 = 800
relation screen / paper = 800 / 200 = 4 <---

screen Height = 400 - 100 = 300
paper Height = 1500 - 1000 = 500
relation screen / paper = 500 / 300 = 1.666... <---


The problem is the relation between the horizontal and vertical increments is not the same:

4 <> 1.666...

This means the Chart will be expanded more in the horizontal dimension than in the vertical dimension.

In this case, Windows increases font sizes and pen widths using the new dimensions.

Note: Windows 16-bit ( 3.1, 3.11 ) do not resize fonts as it does Windows 32-bit (95 and NT). Text can overlap other Chart sections and look bad positioned. To fix this, see below "How to print proportionally?"

Windows 32-bit does a better job using the enhanced metafile format, so text dimensions are calculated precisely.


3- How to Print Proportionally?
-------------------------------

By default, the TChart components are printed using margins that make the paper resulting chart with the same proportions between width and height than the screen chart. This is controlled with the Chart1.PrintProportional
property. The Print Preview dialog has a check-box to set PrintProportional to True or False.

Some printers can show problems when printing Charts *without* using proportional printer margins. Specially in Windows 16-bit with Delphi 1.0 So, the PrintProportional property is recommended to be True (the default).

One approach that allows you full control is to create a metafile image ( TMetafile ) and then Draw the Chart into it, and then send the image to the printer. There is an example included. This is the most low level printing operation you can do.

Another approach is to do the opposite. To resize the Chart onscreen to match the desired proportion of the printed paper chart:

Code: Select all

  Chart1.Height:=Round(1.0*Printer.PageHeight*Chart1.Width/Printer.PageWidth);
  Chart1.Print;

4- Other problems
=====================

Increasing resolution:
----------------------

The metafile format is not aware of the "resolution" concept. This is means resolution information is not stored inside the metafile image.

You can modify the Chart "resolution" *before* printing, by setting this property:

Code: Select all

Chart1.PrintResolution := -100 ;
Negative values (like -100 above), represent the porcentual increment in resolution. Zero means "wysiwyg".

More resolution is obtained by making all Chart fonts smaller and thinner lines. The metafile size is bigger when using more resolution.

Increasing resolution can improve inaccuracy in buggy printer drivers calculations.


Printing non-solid lines:
-------------------------

In some printer / windows combinations, non-solid pen lines such as "dot" or "dash" will be printed as solid. This happens specially in some HP Laserjet printers.

It seems the only workaround is to set the Chart Pen Width properties to Zero:

Code: Select all

Chart1.LeftAxis.Grid.Width := 0;
Increasing resolution ( see above ) can make the printer to show non-solid lines.

Colors:
---------

Many printers accept only a subset of the available Colors. This means setting a Chart color to a non-supported palette color may result in that color not being used by the printer, thus not drawing anything.

In this situations, try with "well known" solid colors like "clRed, clBlue, clYellow, clGreen".

Some printers include a "Color Mapping" configuration dialog. (At Printer Properties dialog).


Printing directly:
------------------

Drawing a Chart directly onto a Printer GDI Handle or Canvas is also possible. The following code does it:

Code: Select all

 Uses Printers;
 With Printer do
 begin 
   BeginDoc;
   try
     Chart1.Draw( Canvas, Rect( 0,0,PageWidth,PageHeight ) );
   finally
     EndDoc;
   end;
 end; 
You will see several problems printing directly:

-- The Chart background is gray color ( instead of white ).
-- Font sizes are extremely small.
-- There are many axis grid lines.
-- Lines are very thin.

One way to solve the above problems is using the metafile printing mode, described in this document.

Another way (much more complicated) is to change all Font sizes and pen Width properties.


Printer driver settings:
------------------------

Try to use always the latest "good" printer driver version. Try changing the Windows Printer driver resolution settings, and the spooler method (in Windows NT) to both "EMF" and "RAW" modes.

"EMF" means all output is sent to the printer in metafile format.



5- Printing Reference
========================

See the help file for extended information and examples on the following properties and methods.

The BASIC.PAS and UPRINT.PAS units in TeeDemo project contain code showing custom printing.

The attached project shows Printing Margin adjustments to avoid text overlaping in Delphi 1.0 on 16-bit Windows systems.

Printing Properties:
---------------------

Properties involved in Chart printing are:

Chart1.PrintMargins
The percentual space at the four sides of the paper page.

Chart1.PrintResolution
The relation between screen dimensions and paper dimensions.

Chart1.PrintProportional
True to set the paper margins to match screen proportions.

Printing methods:
-----------------

The TeeChart control has several methods designed for printing:

Methods that print *and* eject the printed page:
=================================================

These are the default and more used TeeChart printing methods.

Chart1.Print
Uses default paper orientation and margins.

Chart1.PrintPortrait
Sets paper in Portrait and uses default margins.

Chart1.PrintLandscape
Sets paper in Landscape and uses default margins.

Chart1.PrintRect
Uses default paper orientation and the Rect parameter to
position the Chart on the page.


Methods that do not eject the printed page:
============================================

These methods allow printing more than one chart in the same paper page, or print other things and Chart components on the same page.

With these methods you need to call Printer.BeginDoc and EndDoc yourself. See Delphi TPrinter documentation and the UPRINT.PAS and BASIC.PAS units in TeeChart TEEDEMO project.

Chart1.PrintPartial
Draws a Chart to the Printer Canvas at the passed rectangle.

Chart1.PrintPartialCanvas
Draws a Chart to the passed Canvas at the passed rectangle.


Related methods and properties:
===============================

Not directly involved with printing, but useful for advanced printing:

Chart1.Draw
Draws a Chart to the passed Canvas, in screen "mode". "Screen mode" means with gray background and without using the metafile format. This method draws directly to the Canvas.

Chart1.TeeCreateMetafile
Function that returns a metafile image of the Chart, with the passed Rect coordinates.

Chart1.Metafiling
Boolean property indicating the Chart is now drawing onto a metafile image.

Chart1.Printing
Boolean property indicating the Chart is now drawing onto a Printer Canvas.


6- More information:
====================

Information about printing and metafiles can be found at Microsoft Windows 32-bit SDK help file, located at:

"..\Delphi 3(4)\(Borland Shared\Microsoft Help)Help\Win32.hlp"

Use the "Help Contents" (not the index) and scroll-down up to the Metafiles chapter.

See also the Delphi's TMetafile and TMetafileCanvas objects at Delphi's help file and GRAPHICS.PAS unit.

-------------------------------------------------------
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply