천객만래 [千客萬來] (It has an interminable succession of visitors)

'print'에 해당되는 글 2건

  1. 2016.01.08 [개발] C# 인쇄하기
  2. 2010.06.22 [IT/개발] 파워빌더 DataWindow.Print property

[개발] C# 인쇄하기





인쇄하기

GDI+ 인쇄 관련 클래스들을 보자

클래스설명
PageSetupDialog페이지 설정을 처리하는 대화상자. 용지 크기 및 공급, 방향, 여백 등을 설정
PrintDialog컴퓨터에 설치된 프린터를 선택하는 대화상자. 프린터 속성과 인쇄범위 매수 설정
PrintPreviewDialog프린터에 인쇄할 내용 미리보기 대화상자.
PageSettings인쇄될 특정 페이지에 대한 속성 설정.
PrintDocument인쇄될 내용을 담고 있는 개체
PrinterSettings프린터의 색(흑백/컬러), 급지 방식, 가로 인쇄 등의 프린터 속성 설정

인쇄에 관련된 여러 예제들이 있지만 모두 합쳐서 작업해보면 깔끔할 것 같다.

 

응용작업

일기장 프로그램을 만들어서 프린트 할 수 있도록 하는 작업을 해보도록 하자. 윈도우 응용 프로그램으로 새 프로젝트를 만들고 폼에 컨트롤들을 배치한다.

form_layout.gif

 

 

 

 

 

 

 

 

 

 

 

이 폼 레이아웃에서 특별한 점은 없으나 가장 상위의 날짜 입력부분에 들어가는 컨트롤이 DateTimePicker 라는 점이다. 여기에 들어가는 컨트롤들에 대한 아이디는 본인의 임의대로 지정할 수 있으니 편하게 지정하기 바란다.

먼저 네임스페이스와 생성자 이전까지를 본다.

 

  1. 8 using System.Drawing.Imaging;

    9 using System.Drawing.Printing;  // 추가한다.

    10

    11 namespace DiaryPrint

    12 {

    13     public partial class frmDiary : Form

    14     {

    15         private Font m_MainFont = null;

    16         private Font m_SubFont = null;

    17         private Font m_SmallFont = null;

    18         private PageSettings m_PageSetting = null;

    19         private Bitmap m_BackBmp = null;

    20         private Bitmap[] m_Weather = new Bitmap[4];

    21

    22         public frmDiary()

 

다음으로 생성자 내부의 작업을 수행한다.

  1. 24             InitializeComponent();

    25

    26             string FilePath = Application.StartupPath + "\\";

    27             m_MainFont = new Font("돋움", 15, FontStyle.Bold);

    28             m_SubFont = new Font("돋움체", 13);

    29             m_SmallFont = new Font("바탕체", 9);

    30             m_BackBmp = new Bitmap(GetType(), "LetterBackground.jpg");

    31             // 날씨아이콘

    32             for (int i = 0; i < 4; i++)

    33             {

    34                 string strIcon = string.Format("Weather0{0}.gif", i + 1);

    35                 m_Weather[i] = new Bitmap(GetType(), strIcon);

    36             }

    37             cb_Weather.SelectedIndex = 0;

폼 레이아웃에 나와있는 페이지 설정, 미리보기, 인쇄하기 버튼에 대한 이벤트 작성이다.

  1. 40         private void btn_PageSetup_Click(object sender, EventArgs e)

    41         {

    42             try

    43             {

    44                 PageSetupDialog psd = new PageSetupDialog();

    45                 if (this.m_PageSetting == null)

    46                     this.m_PageSetting = new PageSettings();

    47                 psd.PageSettings = this.m_PageSetting;

    48                 psd.ShowDialog();

    49             }

    50             catch (InvalidPrinterException pex)

    51             {

    52                 MessageBox.Show(pex.Message);

    53             }

    54             catch (Exception ex)

    55             {

    56                 MessageBox.Show(ex.Message);

    57             }

    58         }

    59

    60         private void btn_Preview_Click(object sender, EventArgs e)

    61         {

    62             try

    63             {

    64                 PrintDocument pd = new PrintDocument();

    65                 pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

    66

    67                 if (this.m_PageSetting != null)

    68                 {

    69                     pd.DefaultPageSettings = this.m_PageSetting;

    70                 }

    71

    72                 PrintPreviewDialog ppd = new PrintPreviewDialog();

    73                 ppd.Document = pd;

    74                 ppd.ShowDialog();

    75             }

    76             catch (Exception ex)

    77             {

    78                 MessageBox.Show(ex.Message);

    79             }

    80         }

    81

    82         private void btn_Print_Click(object sender, EventArgs e)

    83         {

    84             try

    85             {

    86                 PrintDocument pd = new PrintDocument();

    87                 pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

    88

    89                 if (this.m_PageSetting != null)

    90                 {

    91                     pd.DefaultPageSettings = this.m_PageSetting;

    92                 }

    93

    94                 PrintDialog pdlg = new PrintDialog();

    95                 pdlg.Document = pd;

    96

    97                 if (pdlg.ShowDialog() == DialogResult.OK)

    98                 {

    99                     pd.Print();    // 인쇄

    100                 }

    101             }

    102             catch (Exception ex)

    103             {

    104                 MessageBox.Show(ex.Message);       

    105             }

    106         }

다음으로 가장 핵심 프로세스인 이벤트  pd_PrintPage와 메서드 PaintDocument이다.

  1. 108         protected void pd_PrintPage(object sender, PrintPageEventArgs ppe)

    109         {

    110             Graphics g = ppe.Graphics;

    111             PaintDocument(g);

    112             ppe.HasMorePages = false;

    113         }

    114

    115         private void PaintDocument(Graphics g)

    116         {

    117             g.FillRectangle(Brushes.White, 100, 50, 600, 800);  // 전체 사각형

    118             g.DrawImage(m_BackBmp, 100, 50);    // 배경이미지 출력

    119             g.DrawImage(m_Weather[cb_Weather.SelectedIndex], 380, 120); // 날씨아이콘 출력

    120             g.DrawString(cb_Weather.SelectedItem.ToString(), this.m_MainFont, Brushes.White, 375, 160);   // 날씨적기

    121             g.DrawString(this.dtp_Date.Text, this.m_SubFont, Brushes.Brown, 380, 236);  // 날짜출력

    122

    123             StringFormat sf = new StringFormat();  // 글자포맷

    124             sf.Alignment = StringAlignment.Near;    // 세로정렬

    125             sf.LineAlignment = StringAlignment.Center; // 가로정렬

    126             Rectangle rect = new Rectangle(100, 280, 500, this.m_MainFont.Height * 3); // 제목 적는 영역

    127             g.DrawString(this.txt_Title.Text, this.m_MainFont, Brushes.Black, rect, sf); // 글적기

    128

    129             rect = new Rectangle(240, 350, 500, this.m_SubFont.Height * 10);  // 내용 적는 영역

    130             g.DrawString(this.txt_Contents.Text, this.m_SubFont, Brushes.Black, rect);  // 글 적기

    131         }

닷넷에서 제공하는 프린트에 관련된 핵심 클래스는 다 확인할 수 있으므로 꼭 해보자. 여기에 필요한 이미지는,

LetterBackground.jpgWeather01.gifWeather02.gifWeather03.gifWeather04.gif 총 다섯개 이미지 이다. 받아서 사용해보길 바란다.



PrintDiary.alz


Posted by SB패밀리
DataWindow Object Reference
출처: http://manuals.sybase.com/onlinebooks/group-pbarc/@Generic__CollectionView;lang=ko

DataWindow.Print property

Print.property

Description

Properties that control the printing of a DataWindow.

Applies to

DataWindows

Syntax

PowerBuilder dot notation:

dw_control.Object.DataWindow.Print.property

Describe and Modify argument:

"DataWindow.Print.property { = value }"

SyntaxFromSQL:

DataWindow ( Print.property = value )

Parameter

Description

property

A property for printing. Properties and their settings are listed in the table below

value

The value to be assigned to the property. Value cannot be a DataWindow expression

Property for Print

Value

Collate

Whether printing is collated. Note that collating is usually slower since the print is repeated to produce collated sets. Values are:

  • Yes -- Collate the pages of the print job

  • No -- (Default) Do not collate

The user can specify the value in the system's Print dialog box if the printer driver supports it

Color

An integer indicating whether the printed output will be color or monochrome. Values are:

  • 1 -- Color

  • 2 -- Monochrome

The user can specify the value in the system's Print dialog box if the printer driver supports it

Columns

An integer specifying the number of newspaper-style columns the DataWindow will print on a page. For purposes of page fitting, the whole DataWindow is a single column. The default is 1

Painter: Newspaper Columns Across option

Columns.Width

An integer specifying the width of the newspaper-style columns in the units specified for the DataWindow

Painter: Newspaper Columns Width option

Copies

An integer indicating the number of copies to be printed

The user can also specify this value in the system's Print Setup dialog box if the printer driver supports it

If you use both the Print.Copies property and the Print Setup dialog box to indicate that multiple copies should be printed, the total number of copies printed is the product of both values

DocumentName

A string containing the name that will display in the print queue when the user sends the contents of the DataWindow object to the printer

Painter: Document Name option

Duplex

An integer indicating the orientation of the printed output. Values are:

  • 1 -- Simplex (none)

  • 2 -- Horizontal

  • 3 -- Vertical

The user can specify the value in the system's Print dialog box if the printer driver supports it

Filename

A string containing the name of the file to which you want to print the report. An empty string means send to the printer

Painter: Not settable in painter

Margin.Bottom

An integer indicating the width of the bottom margin on the printed page in the units specified for the DataWindow

You can set Margin.Bottom when using SyntaxFromSQL to generate DataWindow syntax.

Painter: Bottom Margin option

Margin.Left

An integer indicating the width of the left margin on the printed page in the units specified for the DataWindow

You can set Margin.Left when using SyntaxFromSQL to generate DataWindow syntax

Painter: Left Margin option

Margin.Right

An integer indicating the width of the right margin on the printed page in the units specified for the DataWindow

You can set Margin.Right when using SyntaxFromSQL to generate DataWindow syntax

Painter: Right Margin option

Margin.Top

An integer indicating the width of the top margin on the printed page in the units specified for the DataWindow

You can set Margin.Top when using SyntaxFromSQL to generate DataWindow syntax

Painter: Top Margin option

Orientation

An integer indicating the print orientation. Values are:

  • 0 -- The default orientation for your printer

  • 1 -- Landscape

  • 2 -- Portrait

Painter: Paper Orientation option

Page.Range

A string containing the numbers of the pages you want to print, separated by commas. You can also specify a range with a dash. For example, to print pages 1, 2, and 5 through 10, enter: "1,2, 5-10". The empty string means print all

The user can specify the value in the system's Print dialog box if the printer driver supports it

Page. RangeInclude

An integer indicating what pages to print within the desired range. Values are:

  • 0 -- Print all

  • 1 -- Print all even pages

  • 2 -- Print all odd pages

The user can specify the value in the system's Print dialog box if the printer driver supports it

Paper.Size

An integer indicating the size of the paper that will be used for the output:

  • 0 -- Default paper size for the printer

  • 1 -- Letter 8 1/2 x 11 in

  • 2 -- LetterSmall 8 1/2 x 11in

  • 3 -- Tabloid 17 x 11 inches

  • 4 -- Ledger 17 x 11 in

  • 5 -- Legal 8 1/2 x 14 in

  • 6 -- Statement 5 1/2 x 8 1/2 in

  • 7 -- Executive 7 1/4 x 10 1/2 in

  • 8 -- A3 297 x 420 mm

  • 9 -- A4 210 x 297 mm

  • 10 -- A4 Small 210 x 297 mm

  • 11 -- A5 148 x 210 mm

  • 12 -- B4 250 x 354 mm

  • 13 -- B5 182 x 257 mm

  • 14 -- Folio 8 1/2 x 13 in

  • 15 -- Quarto 215 x 275mm

  • 16 -- 10x14 in

  • 17 -- 11x17 in

  • 18 -- Note 8 1/2 x 11 in

  • 19 -- Envelope #9 3 7/8 x 8 7/8

  • 20 -- Envelope #10 4 1/8 x 9 1/2

  • 21 -- Envelope #11 4 1/2 x 10 3/8

  • 22 -- Envelope #12 4 x 11 1/276

  • 23 -- Envelope #14 5 x 11 1/2

  • 24 -- C size sheet

  • 25 -- D size sheet

  • 26 -- E size sheet

  • 27 -- Envelope DL 110 x 220mm

  • 28 -- Envelope C5 162 x 229 mm

  • 29 -- Envelope C3 324 x 458 mm

  • 30 -- Envelope C4 229 x 324 mm

  • 31 -- Envelope C6 114 x 162 mm

  • 32 -- Envelope C65 114 x 229 mm

  • 33 -- Envelope B4 250 x 353 mm

  • 34 -- Envelope B5 176 x 250 mm

  • 35 -- Envelope B6 176 x 125 mm

  • 36 -- Envelope 110 x 230 mm

  • 37 -- Envelope Monarch 3.875 x 7.5 in

  • 38 -- 6 3/4 Envelope 3 5/8 x 6 1/2 in

  • 39 -- US Std Fanfold 14 7/8 x 11 in

  • 40 -- German Std Fanfold 8 1/2 x 12 in

  • 41 -- German Legal Fanfold 8 1/2 x 13 in

Painter: Paper Size option

Paper.Source

An integer indicating the bin that will be used as the paper source. The integer you use depends on the tray number used by the printer. (To determine the actual bin setting, you can query the printer with a utility that makes API calls to the printer driver). Typical values are:

  • 0 -- Default

  • 1 -- Upper

  • 2 -- Lower

  • 3 -- Middle

  • 4 -- Manual

  • 5 -- Envelope

  • 6 -- Envelope manual

  • 7 -- Auto

  • 8 -- Tractor

  • 9 -- Smallfmt

  • 10 -- Largefmt

  • 11 -- Large capacity

  • 14 -- Cassette

Painter: Paper Source option

Preview

Whether the DataWindow object is displayed in preview mode. Values are:

  • Yes -- Display in preview mode

  • No -- (Default) Do not display in preview mode

Preview.Rulers

Whether the rulers display when the DataWindow object displays in preview mode:

  • Yes -- Display the rulers

  • No -- (Default) Do not display the rulers

You can view rulers in Preview mode in the DataWindow painter. Choose File>Print Preview, then File>Print Preview Rulers. However, the setting is not used at runtime. To see rulers during execution, set Print.Preview.Rulers in code

Preview.Zoom

An integer indicating the zoom factor of the print preview. The default is 100%

You can view different zoom percentages in Preview mode in the DataWindow painter. Choose File>Print Preview, then File>Print Preview Zoom. However, the setting is not used at runtime. To change the zoom factor during execution, set Print.Preview.Zoom in code

Prompt

Whether a Printer Setup dialog displays before a job prints so the user can change the paper or other settings for the current printer. Values are:

  • Yes -- (Default) Display a Printer Setup dialog

  • No -- Do not display a Printer Setup dialog

Choosing Cancel in the Printer Setup dialog dismisses the Setup dialog; it does not cancel printing. To allow the user to cancel printing, see the Print method.

For DataStores, this property is ignored; a dialog is never displayed.

Painter: Prompt Before Printing checkbox

Quality

An integer indicating the quality of the output. Values are:

  • 0 -- Default

  • 1 -- High

  • 2 -- Medium

  • 3 -- Low

  • 4 -- Draft

The user can specify the value in the system's Print dialog box if the printer driver supports it

Scale

An integer specifying the scale of the printed output as a percent

The scaling percentage is passed to the print driver. If you have problems with scaling, you may be using a driver that does not support scaling

The user can specify the value in the system's Print dialog box if the printer driver supports it

For more information, see your print driver documentation

Usage

In the painter

Select the DataWindow by deselecting all controls; then set values in the Properties view, Print Specifications tab.

Examples

Example 1

ls_data = dw_1.Object.DataWindow.Print.Scale

Example 2

dw_1.Object.DataWindow.Print.Paper.Size = 3

Example 3

ls_data = dw_1.Describe("DataWindow.Print.Scale")

Example 4

dw_1.Modify("DataWindow.Print.Paper.Size = 3")

Example 5

dw_1.Modify("DataWindow.Print.Margin.Top=500")
Posted by SB패밀리