3

記入しなければならない紙のフォームが大量にストックされています。これを手作業で行うのは非常に面倒なので、アプリケーションを作成しています。データを入力するためのフォームを提供し、印刷プレビューを表示し、紙のフォームにデータを印刷し、履歴を保持できる必要があります。

現在、次のFixedPageように印刷しています。

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));
}

印刷プレビュー用UserControlに、紙のフォームを背景に、データを前景にスキャンした画像を使用したカスタムがあります。基本的に、レイアウトを繰り返しているFixedPageだけで、設計に欠陥があると思わせてしまいます。

私たちが望むことを行うためのより良い方法はありますか?

4

2 に答える 2

2

私は同じ問題を抱えており、時間、単体テスト、および私の正気を節約するために、独自のテンプレート システムを作成することを避けたいと考えていました。

私はハイブリッドを書いて、いくつかのクールなことをしました。まず、HTML と CSS を使用してテンプレートを作成しました。非常に簡単に行うことができ、マーケティング部門が微調整を行う際にも柔軟に対応できました。

テンプレートに独自のタグ ([code_type/]、[day_list]...[/day_list] など) を入力し、文字列を単一または多値のタグの辞書に置き換えました。

html を生成した後、私が見つけた html to pdf ライブラリを使用します。このライブラリは、オープンソースの Webkit エンジンを使用して、生成された pdf をレンダリングおよび作成します。非常に安定していることが判明し、最初のプログラムを作成するのに約 2 週間かかりました。誰もがとても喜んでいて、テストは簡単でした。

詳細が必要な場合は、私にメッセージを送信するか、これに返信してください。

于 2013-03-13T16:16:55.617 に答える
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バインドの代わりに使用する理由は、5 年前のバグです: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=293646

于 2013-03-14T00:40:27.903 に答える