WPF Printing on Server
I was wondering if anyone knew if you can do wpf printing on the server (no UI). The printing features in WPF are great and we are using it to do some report printing on the client, but the customer also wants to be able to trigger a print job to happen on the server.
Is this supported? All the examples I've seen use a print dialog which we wouldn't be able to use.
--
Bryant
Not sure if this will work but try this
public void PrintForm(PrintDialog printDialog)
{
if (printDialog == null) return;
PrintCapabilities printCapabilites = printDialog.PrintQueue.GetPrintCapabilities();
double width = printCapabilites.PageImageableArea.OriginWidth;
double height = printCapabilites.PageImageableArea.OriginHeight;
Size size = new Size(printCapabilites.PageImageableArea.ExtentWidth, printCapabilites.PageImageableArea.ExtentHeight);
Rect rectangle = new Rect(new System.Windows.Point(width, height), size);
this.gridForm.UpdateLayout();
this.gridForm.Measure(size);
this.gridForm.Arrange(rectangle);
XmlElement item = this.DataContext as XmlElement;
printDialog.PrintVisual(this.gridForm, "Incident No. (" + item.GetAttribute("number") + ")");
if (printHistory)
{
PrintableHistory window = new PrintableHistory();
window.DataContext = this.DataContext;
window.PrintForm(printDialog);
}
}
public void PrintForm()
{
PrintForm(new PrintDialog());
Close();
}
What we does is create the window, call the public PrintForm method that prints the form use the PrintDialog that isn't shown.
The big thing that we found is that we had to UpdateLayout, Measure and Arrange only the component (the grid) that we were going to print not the window.
Hey presto, no dialog.
Not sure if this will work from a Windows service.