Mini
Mini

Reputation: 13

Silent printing from WPF

I would like to disable this printing dialog: dialog

What should I do to remove this dialog?

var dlg = new PrintDialog();
dlg.PageRangeSelection = PageRangeSelection.AllPages;
dlg.UserPageRangeEnabled = false;
var doc = new FlowDocument();
    doc.PageWidth = 275;
    doc.FontSize = 18;
    doc.TextAlignment = TextAlignment.Center;
    doc.Blocks.Add(new Paragraph(new Run("nXXXXXXXXXXXX")));
dlg.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "Receipt");

Upvotes: 0

Views: 494

Answers (1)

Mohit
Mohit

Reputation: 2217

You can use PrintDocument class instead of PrintDialog.See the Microsoft's implementation

    try
    {
        streamToPrint = new StreamReader
           ("C:\\My Documents\\MyFile.txt");
        try
        {
            printFont = new Font("Arial", 10);
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler
               (this.pd_PrintPage);
            pd.Print();
        }
        finally
        {
            streamToPrint.Close();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

Upvotes: 2

Related Questions