Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

print, printopt - Print figure or save to file and configure printer defaults

 Contents

GUI Alternative

Select File > Print from the figure window to open the Print dialog box and File > Print Preview to open the Print Preview GUI. For details, see "How to Print or Export" in the MATLAB Graphics documentation.

Syntax

print
print filename
print -ddriver
print -dformat
print -dformat filename
print -smodelname
print -options
print(...)
[pcmd,dev] = printopt

Description

print and printopt produce hard-copy output. All arguments to the print command are optional. You can use them in any combination or order.

print sends the contents of the current figure, including bitmap representations of any user interface controls, to the printer using the device and system printing command defined by printopt.

print filename directs the output to the PostScript file designated by filename. If filename does not include an extension, print appends an appropriate extension.

print -ddriver prints the figure using the specified printer driver, (such as color PostScript). If you omit -ddriver, print uses the default value stored in printopt.m. The table in Printer Drivers lists all supported device types.

print -dformat copies the figure to the system Clipboard (Microsoft Windows platforms only). To be valid, the format for this operation must be either -dmeta (Windows Enhanced Metafile) or -dbitmap (Windows Bitmap).

print -dformat filename exports the figure to the specified file using the specified graphics format (such as TIFF). The table of Graphics Format Files lists all supported graphics file formats.

print -smodelname prints the current Simulink model modelname.

print -options specifies print options that modify the action of the print command. (For example, the -noui option suppresses printing of user interface controls.) Printing Options lists available options.

print(...) is the function form of print. It enables you to pass variables for any input arguments. This form is useful for passing file names and handles. See Batch Processing for an example. Also see Specifying the Figure to Print for further examples.

[pcmd,dev] = printopt returns strings containing the current system-dependent printing command and output device. printopt is an M-file used by print to produce the hard-copy output. You can edit the M-file printopt.m to set your default printer type and destination.

pcmd and dev are platform-dependent strings. pcmd contains the command that print uses to send a file to the printer. dev contains the printer driver or graphics format option for the print command. Their defaults are platform dependent.

Platform

Print Command

Driver or Format

Mac and UNIX

lpr -r

-dps2

Windows

COPY /B %s LPT1:

-dwin

Printer Drivers

The following table shows the more widely used printer drivers supported by MATLAB software. If you do not specify a driver, the default setting shown in the previous table is used. For a list of all supported printer drivers, type print -d at the MATLAB prompt. Some things to remember:

See Selecting the Printer in the Graphics documentation for more information.

Printer Driver

Print Command Option String

Ghostscript

Canon BubbleJet BJ10e

-dbj10e *

Yes

Canon BubbleJet BJ200 color

-dbj200 *

Yes

Canon Color BubbleJet BJC-70/BJC-600/BJC-4000

-dbjc600 *

Yes

Canon Color BubbleJet BJC-800

-dbjc800 *

Yes

Epson and compatible 9- or 24-pin dot matrix print drivers

-depson *

Yes

Epson and compatible 9-pin with interleaved lines (triple resolution)

-deps9high *

Yes

Epson LQ-2550 and compatible; color (not supported on HP-700)

-depsonc *

Yes

Fujitsu 3400/2400/1200

-depsonc *

Yes

HP DesignJet 650C color (not supported on Windows )

-ddnj650c *

Yes

HP DeskJet 500

-ddjet500 *

Yes

HP DeskJet 500C (creates black and white output)

-dcdjmono *

Yes

HP DeskJet 500C (with 24 bit/pixel color and high-quality Floyd-Steinberg color dithering) (not supported on Windows )

-dcdjcolor *

Yes

HP DeskJet 500C/540C color (not supported on Windows )

-dcdj500 *

Yes

HP Deskjet 550C color (not supported on Windows )

-dcdj550 *

Yes

HP DeskJet and DeskJet Plus

-ddeskjet *

Yes

HP LaserJet

-dlaserjet *

Yes

HP LaserJet+

-dljetplus *

Yes

HP LaserJet IIP

-dljet2p *

Yes

HP LaserJet III

-dljet3 *

Yes

HP LaserJet 4, 5L and 5P

-dljet4 *

Yes

HP LaserJet 5 and 6

-dpxlmono *

Yes

HP PaintJet color

-dpaintjet *

Yes

HP PaintJet XL color

-dpjxl *

Yes

HP PaintJet XL color

-dpjetxl *

Yes

HP PaintJet XL300 color (not supported on Windows )

-dpjxl300 *

Yes

HPGL for HP 7475A and other compatible plotters. (Renderer cannot be set to Z-buffer.)

-dhpgl *

No

IBM 9-pin Proprinter

-dibmpro *

Yes

PostScript black and white

-dps

No

PostScript color

-dpsc

No

PostScript Level 2 black and white

-dps2

No

PostScript Level 2 color

-dpsc2

No

Windows color (Windows only)

-dwinc

No

Windows monochrome (Windows only)

-dwin

No

Graphics Format Files

To save your figure as a graphics format file, specify a format switch and file name. To set the resolution of the output file for a built-in MATLAB format, use the -r switch. (For example, -r300 sets the output resolution to 300 dots per inch.) The -r switch is also supported for Windows Enhanced Metafiles, JPEG, TIFF and PNG files, but is not supported for Ghostscript raster formats. For more information, see Printing and Exporting without a Display and Resolution Considerations.

The following table shows the supported output formats for exporting from figures and the switch settings to use. In some cases, a format is available both as a MATLAB output filter and as a Ghostscript output filter. All formats except for EMF are supported on both PC and UNIX platforms.

Graphics Format

Bitmap or Vector

Print Command Option String

MATLAB or Ghostscript

BMP monochrome BMP

Bitmap

-dbmpmono

Ghostscript

BMP 24-bit BMP

Bitmap

-dbmp16m

Ghostscript

BMP 8-bit (256-color) BMP (this format uses a fixed colormap)

Bitmap

-dbmp256

Ghostscript

BMP 24-bit

Bitmap

-dbmp

MATLAB

EMF

Vector

-dmeta

MATLAB

EPS black and white

Vector

-deps

MATLAB

EPS color

Vector

-depsc

MATLAB

EPS Level 2 black and white

Vector

-deps2

MATLAB

EPS Level 2 color

Vector

-depsc2

MATLAB

HDF 24-bit

Bitmap

-dhdf

MATLAB

ILL (Adobe Illustrator)

Vector

-dill

MATLAB

JPEG 24-bit

Bitmap

-djpeg

MATLAB

PBM (plain format) 1-bit

Bitmap

-dpbm

Ghostscript

PBM (raw format) 1-bit

Bitmap

-dpbmraw

Ghostscript

PCX 1-bit

Bitmap

-dpcxmono

Ghostscript

PCX 24-bit color PCX file format, three 8-bit planes

Bitmap

-dpcx24b

Ghostscript

PCX 8-bit newer color PCX file format (256-color)

Bitmap

-dpcx256

Ghostscript

PCX Older color PCX file format (EGA/VGA, 16-color)

Bitmap

-dpcx16

Ghostscript

PDF Color PDF file format

Vector

-dpdf

Ghostscript

PGM Portable Graymap (plain format)

Bitmap

-dpgm

Ghostscript

PGM Portable Graymap (raw format)

Bitmap

-dpgmraw

Ghostscript

PNG 24-bit

Bitmap

-dpng

MATLAB

PPM Portable Pixmap (plain format)

Bitmap

-dppm

Ghostscript

PPM Portable Pixmap (raw format)

Bitmap

-dppmraw

Ghostscript

TIFF 24-bit

Bitmap

-dtiff or -dtiffn

MATLAB

TIFF preview for EPS files

Bitmap

-tiff

 

The TIFF image format is supported on all platforms by almost all word processors for importing images. The -dtiffn variant writes an uncompressed TIFF. JPEG is a lossy, highly compressed format that is supported on all platforms for image processing and for inclusion into HTML documents on the Web. To create these formats, MATLAB renders the figure using the Z-buffer rendering method and the resulting bitmap is then saved to the specified file.

Printing and Exporting without a Display

On a UNIX platform (including Macintosh), where you can start in MATLAB nodisplay mode (matlab -nodisplay), you can print using most of the drivers you can use with a display and export to most of the same file formats. The PostScript and Ghostscript devices all function in nodisplay mode on UNIX platforms. The graphic devices -djpeg, -dpng, -dtiff (compressed TIFF bitmaps), and -tiff (EPS with TIFF preview) work as well, but under nodisplay they use Ghostscript to generate output instead of using the drivers built into MATLAB. However, Ghostscript ignores the -r option when generating -djpeg, -dpng, -dtiff, and -tiff image files. This means that you cannot vary the resolution of image files when running in nodisplay mode.

Naturally, the Windows only -dwin and -dwinc output formats cannot be used on UNIX or Mac platforms with or without a display.

The same holds true on Windows platforms with the -noFigureWindows startup option. The -dwin, -dwinc, and -dsetup options operate as usual under -noFigureWindows. However, the printpreview GUI does not function in this mode.

The formats which you cannot generate in nodisplay mode on UNIX and Mac platforms are:

In addition, uicontrols do not print or export in nodisplay mode.

Printing Options

This table summarizes options that you can specify for print. The second column links to tutorials in Printing and Exporting in the MATLAB Graphics documentation that provide operational details. Also see Resolution Considerations for information on controlling output resolution.

Option

Description

-adobecset

PostScript devices only. Use PostScript default character set encoding. See "Early PostScript 1 Printers".

-append

PostScript devices only. Append figure to existing PostScript file. See "Settings That Are Driver Specific".

-cmyk

PostScript devices only. Print with CMYK colors instead of RGB. See "Setting CMYK Color".

-ddriver

Printing only. Printer driver to use. See Printer Drivers table.

-dformat

Exporting only. Graphics format to use. See "Graphics Format Files" table.

-dsetup

Windows printing only. Display the (platform-specific) Print Setup dialog. Settings you make in it are saved, but nothing is printed.

-fhandle

Handle of figure to print. Note that you cannot specify both this option and the -swindowtitle option. See "Which Figure Is Printed".

-loose

PostScript and Ghostscript printing only. Use loose bounding box for PostScript output. See "Producing Uncropped Figures".

-noui

Suppress printing of user interface controls. See "Excluding User Interface Controls".

-opengl

Render using the OpenGL algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -painters. See "Selecting a Renderer".

-painters

Render using the Painter's algorithm. Note that you cannot specify this method in conjunction with -zbuffer or -opengl. See "Selecting a Renderer".

-Pprinter

Specify name of printer to use. See "Selecting the Printer".

-rnumber

PostScript and built-in raster formats, and Ghostscript vector format only. Specify resolution in dots per inch. Defaults to 90 for Simulink, 150 for figures in image formats and when printing in Z-buffer or OpenGL mode, screen resolution for metafiles, and 864 otherwise. Use -r0 to specify screen resolution. For details, see Resolution Considerations and "Setting the Resolution".

-swindowtitle

Specify name of Simulink system window to print. Note that you cannot specify both this option and the -fhandle option. See "Which Figure Is Printed".

-v

Windows printing only. Display the Windows Print dialog box. The v stands for "verbose mode."

-zbuffer

Render using the Z-buffer algorithm. Note that you cannot specify this method in conjunction with -opengl or -painters. See "Selecting a Renderer".

Resolution Considerations

Use -rnumber to specify the resolution of the generated output. In general, using a higher value will yield higher quality output but at the cost of larger output files. It affects the resolution and output size of all MATLAB built-in raster formats (which are identified in column four of the table in Graphics Format Files).

Unlike the built-in MATLAB formats, graphic output generated via Ghostscript does not directly obey -r option settings. However, the intermediate PostScript file generated by MATLAB as input for the Ghostscript processor is affected by the -r setting and thus can indirectly influence the quality of the final Ghostscript generated output.

The effect of the -r option on output quality can be subtle at ordinary magnification when using the OpenGL or ZBuffer renderers and writing to one of the MATLAB built-in raster formats, or when generating vector output that contains an embedded raster image (for example, PostScript or PDF). The effect of specifying higher resolution is more apparent when viewing the output at higher magnification or when printed, since a larger -r setting provides more data to use when scaling the image.

When generating fully vectorized output (as when using the Painters renderer to output a vector format such as PostScript or PDF), the resolution setting affects the degree of detail of the output; setting resolution higher generates crisper output (but small changes in the resolution may have no observable effect). For example, the gap widths of lines that do not use a solid ('-') linestyle can be affected.

Paper Sizes

MATLAB printing supports a number of standard paper sizes. You can select from the following list by setting the PaperType property of the figure or selecting a supported paper size from the Print dialog box.

Property Value

Size (Width by Height)

usletter

8.5 by 11 inches

uslegal

8.5 by 14 inches

tabloid

11 by 17 inches

A0

841 by 1189 mm

A1

594 by 841 mm

A2

420 by 594 mm

A3

297 by 420 mm

A4

210 by 297 mm

A5

148 by 210 mm

B0

1029 by 1456 mm

B1

728 by 1028 mm

B2

514 by 728 mm

B3

364 by 514 mm

B4

257 by 364 mm

B5

182 by 257 mm

arch-A

9 by 12 inches

arch-B

12 by 18 inches

arch-C

18 by 24 inches

arch-D

24 by 36 inches

arch-E

36 by 48 inches

A

8.5 by 11 inches

B

11 by 17 inches

C

17 by 22 inches

D

22 by 34 inches

E

34 by 43 inches

Printing Tips

Figures with Resize Functions

The print command produces a warning when you print a figure having a callback routine defined for the figure ResizeFcn. To avoid the warning, set the figure PaperPositionMode property to auto or select Match Figure Screen Size in the File > Page Setup dialog box.

Troubleshooting Microsoft Windows Printing

If you encounter problems such as segmentation violations, general protection faults, or application errors, or the output does not appear as you expect when using Microsoft printer drivers, try the following:

Printing MATLAB GUIs

You can generally obtain better results when printing a figure window that contains MATLAB uicontrols by setting these key properties:

If you print or export in nodisplay mode, none of the uicontrols the figure has will be visible. If you run code that adds uicontrols to a figure when the figure is invisible, the controls will not print until the figure is made visible.

Printing Interpolated Shading with PostScript Drivers

You can print MATLAB surface objects (such as graphs created with surf or mesh) using interpolated colors. However, only patch objects that are composed of triangular faces can be printed using interpolated shading.

Printed output is always interpolated in RGB space, not in the colormap colors. This means that if you are using indexed color and interpolated face coloring, the printed output can look different from what is displayed on screen.

PostScript files generated for interpolated shading contain the color information of the graphics object's vertices and require the printer to perform the interpolation calculations. This can take an excessive amount of time and in some cases, printers might time out before finishing the print job. One solution to this problem is to interpolate the data and generate a greater number of faces, which can then be flat shaded.

To ensure that the printed output matches what you see on the screen, print using the -zbuffer option. To obtain higher resolution (for example, to make text look better), use the -r option to increase the resolution. There is, however, a tradeoff between the resolution and the size of the created PostScript file, which can be quite large at higher resolutions. The default resolution of 150 dpi generally produces good results. You can reduce the size of the output file by making the figure smaller before printing it and setting the figure PaperPositionMode to auto, or by just setting the PaperPosition property to a smaller size.

Examples

Specifying the Figure to Print

You can print a noncurrent figure by specifying the figure's handle. If a figure has the title "Figure 2", its handle is 2. The syntax is:

print -fhandle 

This example prints the figure whose handle is 2, regardless of which figure is the current figure:

print -f2

This example saves the figure with the handle -f2 to a PostScript file named Figure2, which can be printed later:

print -f2 -dps 'Figure2.ps'

If the figure uses noninteger handles, use the figure command to get its value, and then pass it in as the first argument. For example:

h = figure('IntegerHandle','off')
print h -dps2

You can also pass a figure handle as a variable to the function form of print. For example:

h = figure; plot(1:4,5:8)
print(h)

This example uses the function form of print to enable a file name to be passed in as a variable:

filename = 'mydata';
print('-f3', '-dpsc', filename);

(Because a file name is specified, the figure will be printed to a file.)

This example combines the previous two examples and uses the function form to print using both a handle variable and a file name variable:

h = figure; plot(1:4,5:8)
filename = 'mydata';
print(h, '-dpsc', filename);

(Because a file name is specified, the figure will be printed to a file.)

Specifying the Model to Print

To print a noncurrent Simulink model, use the -s option with the title of the window. For example, this command prints the Simulink window titled f14:

print -sf14

If the window title includes any spaces, you must call the function form rather than the command form of print. For example, this command saves the Simulink window title Thruster Control:

print('-sThruster Control')

To print the current system, use:

print -s

For information about issues specific to printing Simulink windows, see the Simulink documentation.

Printing Figures at Screen Size

This example prints a surface plot with interpolated shading. Setting the current figure's (gcf) PaperPositionMode to auto enables you to resize the figure window and print it at the size you see on the screen. See Printing Options and Printing Interpolated Shading with PostScript Drivers for information on the -zbuffer and -r200 options.

surf(peaks)
shading interp
set(gcf,'PaperPositionMode','auto')
print -dpsc2 -zbuffer -r200

For additional details, see "Printing Images" in the MATLAB Graphics documentation.

Batch Processing

You can use the function form of print to pass variables containing file names. For example, this for loop uses file names stored in a cell array to create a series of graphs and prints each one with a different file name:

fnames = {'file1', 'file2', 'file3'};
for k=1:length(fnames)
    surf(peaks)
    print('-dtiff','-r200',fnames{k})
end

Tiff Preview

The command

print -depsc -tiff -r300 picture1

saves the current figure at 300 dpi, in a color Encapsulated PostScript file named picture1.eps. The -tiff option creates a 72 dpi TIFF preview, which many word processor applications can display on screen after you import the EPS file. This enables you to view the picture on screen within your word processor and print the document to a PostScript printer using a resolution of 300 dpi.

See Also

figure, hgsave, imwrite, orient, printdlg, printopt, saveas

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS