views:

180

answers:

3

I need to build an application that accepts user input data (such as name, address, amount, etc.) and then merges it with a pre-loaded document template (order form) and then prints this merged document. I can use Windows Forms or WPF for this project.

Any suggestions on how best to approach this? I'm experienced with Winforms development, but don't have any idea how to handle merging the data to the document for printing.

+1  A: 

WPF works great for this.

You can create document templates from WPF UI elements such as a Page or a UserControl. Set up the template like you'd set up any UI in the VS designer. Determine what shape your data will be stored in (this will be your DataContext), then bind against its public properties. Then you can drop your merged template into a FixedPage and add it to an XPS document. You can print that very easily or save it to disk.

Simplified algorithm:

  • Create a data entry form.
  • Create a type that will hold data from the form (call this type Foo)
  • Create a Page template that binds against Foo (when a Foo instance is the DataContext)
  • Bind the form to an instance of Foo
  • Have the user fill in the form (and thereby the instance of Foo)
  • Create an instance of your template (assume its a Page)
  • Set Page.DataContext = fooInstance;
  • Add the Page to a FixedPage, then add this to a Fixed Document
  • Save the FixedDocument to an XPS document
  • Save the XPS document or send it to a PrintQueue

I'm doing something similar to this and it works well. Just go to my profile and read all my questions. They cover most of the hard bits of the whole procedure.

Will
A: 

You need to use Mail Merge. A mail merge is a method of taking data from a database, spreadsheet, or other form of structured data, and inserting it into documents such as letters, mailing labels, and name tags. Start from this article.

Jacob Seleznev
A: 

Will, I appreciate your answer. Thank you!

MikeZ