첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형
using DevExpress.Office.Utils;
using DevExpress.XtraPrinting;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

#region Print 버튼 클릭시 처리하기 - printButton_Click(sender, e)

/// <summary>
/// Print 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void printButton_Click(object sender, EventArgs e)
{
    RichEditDocumentServer richEditDocumentServer = new RichEditDocumentServer();

    richEditDocumentServer.Document.DefaultParagraphProperties.Alignment = ParagraphAlignment.Center;
    richEditDocumentServer.Document.Sections[0].Page.Landscape           = true;
    richEditDocumentServer.Document.Sections[0].Page.Height              = Units.InchesToDocumentsF(10.0f);
    richEditDocumentServer.Document.Sections[0].Page.Width               = Units.InchesToDocumentsF(4.5f);

    richEditDocumentServer.Document.AppendText("This content is created programmatically\n");

    richEditDocumentServer.Document.AppendParagraph();

    InsertTable(richEditDocumentServer);

    using(PrintingSystem printingSystem = new PrintingSystem())
    {
        using(PrintableComponentLink printableComponentLink = new PrintableComponentLink(printingSystem))
        {
            printableComponentLink.Component = richEditDocumentServer;

            printableComponentLink.CreateDocument();

            printableComponentLink.ShowPreviewDialog();
        }
    }
}

#endregion

#region 테이블 삽입하기 - InsertTable(richEditDocumentServer)

/// <summary>
/// 테이블 삽입하기
/// </summary>
/// <param name="richEditDocumentServer">RichEditDocumentServer</param>
private void InsertTable(RichEditDocumentServer richEditDocumentServer)
{
    richEditDocumentServer.BeginUpdate();
            
    Table table = richEditDocumentServer.Document.Tables.Add(richEditDocumentServer.Document.Selection.Start, 8, 8, AutoFitBehaviorType.FixedColumnWidth);

    table.BeginUpdate();

    table.Borders.InsideHorizontalBorder.LineThickness = 1;
    table.Borders.InsideHorizontalBorder.LineStyle     = TableBorderLineStyle.Double;
    table.Borders.InsideVerticalBorder.LineThickness   = 1;
    table.Borders.InsideVerticalBorder.LineStyle       = TableBorderLineStyle.Double;
    table.TableAlignment                               = TableRowAlignment.Center;

    table.ForEachCell
    (
        new TableCellProcessorDelegate
        (
            delegate(TableCell tableCell, int rowIndex, int columnIndex)
            {
                richEditDocumentServer.Document.InsertText
                (
                    tableCell.Range.Start,
                    string.Format("{0}×{1} : {2}", rowIndex + 2, columnIndex + 2, (rowIndex + 2) * (columnIndex + 2))
                );
            }
        )
    );

    table.EndUpdate();

    richEditDocumentServer.EndUpdate();
}

#endregion
728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요