Reputation: 88
I have a class like this in my WPF application, here I want to assign the Print settings like the Page size, tray without showing the dialogbox to the user. I am able to get set the other values except for the Print tray it would be of great help if anyone could help me on this.
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
public class Print
{
/// <summary>
/// Initializes a new instance of the <see cref="Print"/> class.
/// </summary>
public Print() { }
/// <summary>
/// Prints the document.
/// </summary>
/// <param name="outputStream">The output stream.</param>
public void PrintDocument(MemoryStream outputStream)
{
FlowDocument fd = new FlowDocument();
TextRange tr = new TextRange(fd.ContentStart, fd.ContentEnd);
tr.Load(outputStream, DataFormats.Rtf);
PrintDialog printDlg = new PrintDialog();
fd.PageHeight = printDlg.PrintableAreaHeight;
fd.PageWidth = printDlg.PrintableAreaWidth;
fd.PagePadding = new Thickness(25);
fd.ColumnGap = 0;
fd.ColumnWidth = (fd.PageWidth -
fd.ColumnGap -
fd.PagePadding.Left -
fd.PagePadding.Right);
if (printDlg.ShowDialog() == true)
{
IDocumentPaginatorSource idpSource = fd;
idpSource.DocumentPaginator.PageSize = new Size { Height = 600, Width = 600 };
printDlg.PrintDocument(idpSource.DocumentPaginator, "Printing Document");
}
}
Upvotes: 0
Views: 589
Reputation: 35
Please use following code to set default Page Size in C#
PaperSize paperSize = new PaperSize("papersize", 200, 100);//set the paper size
PaperSize accepts parameters NewPageSizeName, Width, Height
Upvotes: 1