첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
    xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
    xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit" 
    Width="800"
    Height="600"
    Title="이미지 문서 인쇄하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <ResourceDictionary>
            <dxre:RichEditUICommand x:Key="RichEditUICommandKey" />
            <dxre:RichEditStringIdConverter x:Key="RichEditStringIdConverterKey" />
            <dxre:DefaultBarItemDataTemplates x:Key="DefaultBarItemDataTemplatesKey" />
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <dxb:BarManager x:Name="barManager"
            ToolbarGlyphSize="Small">
            <dxb:BarManager.Items>
                <dxb:BarButtonItem x:Name="fileNewBarButtonItem"
                    Command="{Binding Path=FileNew,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileOpenBarButtonItem"
                    Command="{Binding Path=FileOpen,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileSaveBarButtonItem"
                    Command="{Binding Path=FileSave,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileSaveAsBarButtonItem"
                    Command="{Binding Path=FileSaveAs,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="fileQuickPrintBarButtonItem"
                    Command="{Binding Path=FileQuickPrint,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="filePrintBarButtonItem"
                    Command="{Binding Path=FilePrint,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="filePrintPreviewBarButtonItem"
                    Command="{Binding Path=FilePrintPreview,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editUndoBarButtonItem"
                    Command="{Binding Path=EditUndo,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="editRedoBarButtonItem"
                    Command="{Binding Path=EditRedo,
                    Mode=OneTime,
                    Source={StaticResource RichEditUICommandKey}}" />
                <dxb:BarButtonItem x:Name="saveAsImageBarButtonItem"
                    Content="Save As Image"
                    ItemClick="saveAsImageBarButtonItem_ItemClick" />
            </dxb:BarManager.Items>
            <DockPanel>
                <dxr:RibbonControl x:Name="ribbonControl" DockPanel.Dock="Top">
                    <dxr:RibbonDefaultPageCategory>
                        <dxr:RibbonPage x:Name="fileRibbonPage"
                            Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                ConverterParameter=Caption_PageFile, Converter={StaticResource RichEditStringIdConverterKey}, Mode=OneTime}">
                            <dxr:RibbonPageGroup x:Name="fileCommonRibbonPageGroup"
                                ShowCaptionButton="False"
                                Caption="{Binding Source={StaticResource RichEditStringIdConverterKey},
                                    ConverterParameter=Caption_GroupCommon,
                                    Converter={StaticResource RichEditStringIdConverterKey},
                                    Mode=OneTime}">
                                <dxb:BarButtonItemLink BarItemName="fileNewBarButtonItem"          />
                                <dxb:BarButtonItemLink BarItemName="fileOpenBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="fileSaveBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="fileSaveAsBarButtonItem"       />
                                <dxb:BarButtonItemLink BarItemName="fileQuickPrintBarButtonItem"   />
                                <dxb:BarButtonItemLink BarItemName="filePrintBarButtonItem"        />
                                <dxb:BarButtonItemLink BarItemName="filePrintPreviewBarButtonItem" />
                                <dxb:BarButtonItemLink BarItemName="editUndoBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="editRedoBarButtonItem"         />
                                <dxb:BarButtonItemLink BarItemName="saveAsImageBarButtonItem"      />
                            </dxr:RibbonPageGroup>
                        </dxr:RibbonPage>
                    </dxr:RibbonDefaultPageCategory>
                </dxr:RibbonControl>
                <dxre:RichEditControl x:Name="richEditControl"
                    BarManager="{Binding ElementName=barManager, Mode=OneTime}"
                    Ribbon="{Binding ElementName=ribbonControl, Mode=OneTime}"
                    Loaded="richEditControl_Loaded" />
            </DockPanel>
        </dxb:BarManager>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Drawing.Imaging;
using System.Windows;
using System.Windows.Input;

using DevExpress.Xpf.Bars;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrintingLinks;
using DevExpress.XtraRichEdit;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 리치 에디트 컨트롤 로드시 처리하기 - richEditControl_Loaded(sender, e)

        /// <summary>
        /// 리치 에디트 컨트롤 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void richEditControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.richEditControl.LoadDocument("test.docx");
        }

        #endregion
        #region Save As Image 바 버튼 항목 항목 클릭시 처리하기 - saveAsImageBarButtonItem_ItemClick(sender, e)

        /// <summary>
        /// Save As Image 바 버튼 항목 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void saveAsImageBarButtonItem_ItemClick(object sender, ItemClickEventArgs e)
        {
            Cursor = Cursors.Wait;

            PrintableComponentLinkBase printableComponentLinkBase = new PrintableComponentLinkBase(new PrintingSystemBase());

            printableComponentLinkBase.Component = (this.richEditControl as IRichEditControl).InnerControl;

            printableComponentLinkBase.CreateDocument(false);

            ImageExportOptions imageExportOptions = new ImageExportOptions();

            imageExportOptions.ExportMode = ImageExportMode.DifferentFiles;
            imageExportOptions.Format     = ImageFormat.Png;
            imageExportOptions.Resolution = 150;
            imageExportOptions.PageRange  = "1,3-5";

            printableComponentLinkBase.ExportToImage("export.png", imageExportOptions);

            Cursor = Cursors.Arrow;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요