The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[UWP]Print Document direct to selected printer from UWP RRS feed

  • Question

  • I can print directly to a selected printer, a document ?. I already have the list of all printers local and sharing and the idea is that it depends of type of document is going to add a specify printer, so that the user does not need to do it for himself. For example bills printed on your local printer and report on the network printer




    Sunday, April 17, 2016 6:57 PM

Answers

  • Thank you for your help, but this is not what I want, at this moment, because the local printer is connected via USB, but I found a solution with I am satisfied, it is to change the default printed before opening the Print UI.

    Based on this article https://support.microsoft.com/en-us/kb/322091

    public static class DefPrinters
    {
        [DllImport("C:\\Windows\\System32\\winspool.drv")]
        public static extern bool SetDefaultPrinter(string Name);
    
    }


    private void DefaultPrinter_Click(object sender, RoutedEventArgs e)
            {
                string printername = this.comboBox.SelectedItem.ToString();
                DefPrinters.SetDefaultPrinter(printername);
            }



    • Proposed as answer by Xavier Xie-MSFT Friday, April 22, 2016 2:12 AM
    • Edited by Vizaint Friday, April 22, 2016 8:41 AM
    • Marked as answer by Vizaint Friday, April 22, 2016 8:50 AM
    Thursday, April 21, 2016 10:17 PM

All replies

  • Hi Vizaint,

    If you want to use "Windows.UI.Xaml.Printing" to print your documents, I afraid you cannot print them directly. You would have to show the print dialog, it's by design. But I think you could try to think about using Sockets to communicate with your devices directly.

    Here's "Sockets" document for your details: https://msdn.microsoft.com/en-us/windows/uwp/networking/sockets

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 18, 2016 10:47 AM
  • Thank you for your help, but this is not what I want, at this moment, because the local printer is connected via USB, but I found a solution with I am satisfied, it is to change the default printed before opening the Print UI.

    Based on this article https://support.microsoft.com/en-us/kb/322091

    public static class DefPrinters
    {
        [DllImport("C:\\Windows\\System32\\winspool.drv")]
        public static extern bool SetDefaultPrinter(string Name);
    
    }


    private void DefaultPrinter_Click(object sender, RoutedEventArgs e)
            {
                string printername = this.comboBox.SelectedItem.ToString();
                DefPrinters.SetDefaultPrinter(printername);
            }



    • Proposed as answer by Xavier Xie-MSFT Friday, April 22, 2016 2:12 AM
    • Edited by Vizaint Friday, April 22, 2016 8:41 AM
    • Marked as answer by Vizaint Friday, April 22, 2016 8:50 AM
    Thursday, April 21, 2016 10:17 PM
  • Hi Vizaint,

    Thank you for sharing your solution with us.

    You could mark it as answer. It would be helpful to other developers to find the answer of the similar questions.

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 22, 2016 2:14 AM
  • Thank you for your help, but this is not what I want, at this moment, because the local printer is connected via USB, but I found a solution with I am satisfied, it is to change the default printed before opening the Print UI.

    Based on this article

    public static class DefPrinters
    {
        [DllImport("C:\\Windows\\System32\\winspool.drv")]
        public static extern bool SetDefaultPrinter(string Name);
    
    }


    private void DefaultPrinter_Click(object sender, RoutedEventArgs e)
            {
                string printername = this.comboBox.SelectedItem.ToString();
                DefPrinters.SetDefaultPrinter(printername);
            }



    When will the DefaultPrinter_Click be called? 
    Friday, September 20, 2019 8:16 AM