22
Printing Support in the .NET Framework The PrintDocument object MikeFITZSIMON SYSTEMSARCHITECT FITZSIMON IT CONSULTING PTY LTD

Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

  • View
    216

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Printing Support in the .NET Framework

The PrintDocument object MikeFITZSIMONSYSTEMSARCHITECT

FITZSIMON IT CONSULTING PTY LTD

Page 2: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing from .NETWHY? Why not…

print reports with Crystal Reports? or Access? automate Word? print charts from Excel?

Specialist printers, eg, label / ID card printers Print to more than one printer at once Complex tray pulls Graphics, CAD, Charting, GIS applications To give your users ultimate control over

report layout.

Page 3: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 4: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 5: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Overview(all you need to know) Create a new PrintDocument object Set printer settings through the PrinterSettings property

Set page settings through the DefaultPageSettings property

Call the Print method to start the printing process

Handle the PrintPage event where you specify the output to print, by using the Graphics object included in the PrintPageEventArgs

Page 6: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 7: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 8: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Basic Printing: create a new PrintDocument object Either drag an instance of the PrintDocument

object directly from the Toolbox to the designer at design time …

or use code at run time. Visual Basic .NET

Imports System.Drawing.PrintingDim myPrintDocument As _ New PrintDocument()

Visual C#

using System.Drawing.Printing; PrintDocument myPrintDocument = new PrintDocument();

Uses default settings on the default printer

Page 9: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Basic Printing: the PrintPage event and its handler Call the Print method to start printingPrintDoc1.Print()

One PrintPage event is raised for each page Handle this yourself Use the PrintPageEventArgs.Graphics object

to specify the output to print Private Sub PrintDoc1_PrintPage( _ ByVal sender As System.Object, _ ByVal e As PrintPageEventArgs) _ Handles PrintDoc1.PrintPage... e.Graphics.DrawString( _ "G'day World", ... e.HasMorePages = FalseEnd Sub

Page 10: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 11: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 12: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Print Code Demos…

Page 13: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 14: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 15: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

PrintDemo

Printing Text ppea.Graphics.DrawString("text", ...

Printing Images, logos, iconsLogoImage = _ Image.FromFile("..\FITCLogoLH.wmf")ppea.Graphics.DrawImage(LogoImage, _ ulCorner)

Printing Vector Graphics, polygons, lines, rectangles myPath.AddPolygon(... ppea.Graphics.DrawPath(Pens.Black, _ myPath)

Page 16: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 17: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printer Settings

Create a new PrintDialog object Dim pdlg as NEW PrintDialog()

Associate PrintDocument object with the PrintDialog pdlg.Document = pd

Show the PrintDialog and then print with the new PrinterSettingsIf pdlg.ShowDialog() = _ DialogResult.OK Then pd.Print()

Page 18: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Page Setup

Create a new PageSetupDialog objectDim pdlg as NEW PageSetupDialog()

Associate PrintDocument object with the PageSetupDialog pdlg.Document = pd

Show the PageSetupDialog and then print with the new PrinterSettingsIf pdlg.ShowDialog() = _ DialogResult.OK Then ...

Page 19: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Run Time settings

Printer settings can be set at run time, eg,pd.PrinterSettings.PrinterName = _ "WinFax"

The PrinterSettings.InstalledPrinters property holds the list of all printers installed on the computer

Page settings can be set at run time in a PrintPage event handler, eg,ppea.Pagesettings.Landscape = True

Page 20: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Printing Support in the .NET Framework Printing Overview Basic Printing, step by step The “G’Day World” printing program PrintDemo, a more complex printing example

Text (fonts) Vector Graphics (lines & splines) Images (bitmaps, metafiles, icons)

Printer settings & Page Setup Print Preview

Page 21: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Print Preview

Create a new PrintPreviewDialog objectDim pdlg as NEW _ PrintPreviewDialog()

Associate a PrintDocument object with the PrintPreviewDialog pdlg.Document = pd

Show the PrintPreviewDialog pdlg.ShowDialog()

Be prepared to execute all your PrintPage events again.

Page 22: Printing Support in the.NET Framework The PrintDocument object Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD

Fitzsimon IT CONSULTING PTY LTD www.fitzsimon.com.au

Questions

Mike [email protected]

Sample code & this ppt available fromwww.fitzsimon.com.au/qmsdnug

No trees were harmed in the presentation of this session, however…

a number of electrons were told exactly where to go.