2013-03-13 2 views
3

우리는 작성해야 할 종이 양식이 많이 있습니다. 이 작업을 손으로 수행하는 것은 매우 지루하므로 응용 프로그램을 구축합니다. 데이터를 채우고 인쇄 미리보기를 표시하고 종이 양식에 데이터를 인쇄하고 기록을 유지할 수있는 양식을 제공해야합니다. 우리가 배경에 종이 형태와 전경에있는 데이터의 스캔 이미지와 사용자 정의 UserControl가 인쇄 미리보기를미리보기가있는 종이 양식에 인쇄하기

var dlg = new PrintDialog(); 
if (dlg.ShowDialog() == true) 
{ 
    var doc = new FixedDocument(); 
    doc.DocumentPaginator.PageSize = new Size(11.69 * 96, 8.27 * 96); // A4 Landscape 

    var fp = Application.LoadComponent(new Uri("/FixedPage.xaml", UriKind.Relative)) as FixedPage; 
    fp.DataContext = this; 
    fp.UpdateLayout(); 

    var pc = new PageContent(); 
    ((IAddChild)pc).AddChild(fp); 
    doc.Pages.Add(pc); 

    dlg.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape; 
    dlg.PrintDocument(doc.DocumentPaginator, string.Format("Form #{0}", FormNumber)); 
} 

:

현재, 우리는 우리가 같이 인쇄 이는 FixedPage 있습니다. 기본적으로, 그것은 FixedPage 레이아웃을 되풀이하고 있습니다.이 모든 것이 우리 디자인에 결함이 있다고 생각하게 만듭니다.

우리가 원하는 것을 할 수있는 더 좋은 방법이 있습니까?

+1

당신이 혜택을 누릴 수 있다고 생각 http://stackoverflow.com/questions/404010/use-of-print-preview-in-net-winforms 인쇄 및 미리보기를 위해 동일한 방법을 사용하는 것이 가장 좋은 방법이라고 생각합니다. 나는 PrintDialog를 직접 사용하지 않았다. 그러나 종이가 아닌 미리보기로 인쇄하려면 멀리 있어야합니다. 그저 다른 종류의 기기 일 수도 있습니다. – Dzyann

+0

@Dzyann, 감사합니다. 그러나 용지에 인쇄하지 않고 어떻게 미리보기에 배경 이미지를 표시 할 것인지 잘 모르겠습니다. 샘플을 제공하면 대답으로 받아 들여서 기쁩니다. – Joulukuusi

+0

레이아웃에 사용하는 사용자 정의 컨트롤에 Canvas가 있고, 스캔 된 이미지의 배경과 함께 FixedPage.xmal을 직접 사용하는 cambas를 사용할 수 있습니까? – Dzyann

답변

1

우리는 많은 코드를 폐기 할 수있는 솔루션을 찾을 수있었습니다. 아직 못생긴 :

public class CustomDocumentViewer : DocumentViewer 
{ 
    public static readonly DependencyProperty BackgroundImageProperty = 
     DependencyProperty.Register("BackgroundImage", typeof(Image), typeof(CustomDocumentViewer), new UIPropertyMetadata(null)); 

    public Image BackgroundImage 
    { 
     get { return GetValue(BackgroundImageProperty) as Image; } 
     set { SetValue(BackgroundImageProperty, value); } 
    } 

    protected override void OnDocumentChanged() 
    { 
     (Document as FixedDocument).Pages[0].Child.Children.Insert(0, BackgroundImage); 
     base.OnDocumentChanged(); 
    } 

    protected override void OnPrintCommand() 
    { 
     var printDialog = new PrintDialog(); 
     if (printDialog.ShowDialog() == true) 
     { 
      (Document as FixedDocument).Pages[0].Child.Children.RemoveAt(0); 
      printDialog.PrintDocument(Document.DocumentPaginator, "Test page"); 
      (Document as FixedDocument).Pages[0].Child.Children.Insert(0, BackgroundImage); 
     } 
    } 
} 

... 

<local:CustomDocumentViewer x:Name="viewer" BackgroundImage="{StaticResource PaperFormImage}"/> 

... 

InitializeComponent(); 
viewer.Document = Application.LoadComponent(new Uri("/PaperFormDocument.xaml", UriKind.Relative)) as IDocumentPaginatorSource; 

우리가 Application.LoadComponent를 사용하는 대신 구속력있는 이유는 다섯 살 버그 : http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293646

2

나는 동일한 문제를 안고 있으며 시간, 단위 테스트 및 나의 온건함을 절약하기 위해 내 자신의 템플릿 시스템을 작성하는 것을 피하고자했습니다.

나는 멋진 물건을 만들기 위해 잡종을 쓰는 것을 끝내었다. 먼저 HTML과 CSS를 사용하여 템플릿을 작성했습니다. 마케팅 부서에서 사소한 조정을 할 때 매우 유연하게 적용 할 수있었습니다.

템플릿을 내 자신의 태그 (예 : [code_type /], [day_list] ... [/ day_list])로 채웠고 문자열은 텍스트를 단일 또는 다중 값일 수있는 태그 사전으로 교체했습니다.

html을 생성 한 후에는 오픈 소스 웹킷 엔진을 사용하여 생성 된 PDF를 렌더링하고 생성하는 html to pdf 라이브러리를 사용합니다. 그것은 매우 안정적이었고 초기 프로그램을 작성하는 데 약 2 주가 걸렸습니다. 모두가 매우 기뻤고 테스트는 산들 바람이었습니다.

자세한 내용을 원하시면 저에게 메시지를 보내거나 이에 대한 회신을 보내주십시오.

+0

인쇄 미리보기를 어떻게 보이셨습니까? 나는 여전히 두 개의 다른 템플릿이 필요하다고 생각한다. 하나는 배경 이미지 (미리보기), 하나는없는 것 (인쇄)이다. – Joulukuusi

+0

나는 그렇지 않았다. 방금 html로 렌더링했습니다. :) – tylerjgarland