locked
How to Print in Windows Store App C# RRS feed

  • Question

  • Hello, I would like to print a single picture in a Windows Store App. I would like to have the pictures take up the entire piece of paper. How can I go about this? Thank You.

    Sincerely, Jakeinc

    Sunday, November 10, 2013 10:55 PM

Answers

  • Hi Jakeinc,

    PreparePrintContent() is a virtual method, and could be override, if you take a look at scenario 1 to 5, you will able to see the override method like below, it could be used to manage the layout of the print stuff, such as adding the header, but in scenario 6 there is nothing to do with the image, that's why the method leave blank.

            protected override void PreparePrintContent()
            {
                if (firstPage == null)
                {
                    firstPage = new ScenarioOutput1();
                    StackPanel header = (StackPanel)firstPage.FindName("header");
                    header.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
    
                // Add the (newley created) page to the printing root which is part of the visual tree and force it to go
                // through layout so that the linked containers correctly distribute the content inside them.
                PrintingRoot.Children.Add(firstPage);
                PrintingRoot.InvalidateMeasure();
                PrintingRoot.UpdateLayout();
            }
    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Jamles HezModerator Friday, November 22, 2013 9:28 AM
    • Marked as answer by Jakeinc Friday, November 22, 2013 7:46 PM
    • Unmarked as answer by Jakeinc Saturday, November 23, 2013 6:30 PM
    • Marked as answer by Jakeinc Saturday, November 23, 2013 9:11 PM
    Tuesday, November 19, 2013 2:05 AM
    Moderator

All replies

  • Hi Jakeinc,

    I think the following article could be a good start for you:Quickstart: Printing from your app, in the 4th step, you could format your printing page, where you could set a image in AddPage method.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, November 11, 2013 2:03 AM
    Moderator
  • Thank You. I have tried to modify the code to work, but it always breaks at

    header.Visibility = Window.Current.Content.Visibility;

    With "Object reference not set to an instance of an object." What should I do about this? Also, I can post the entire code if you would like, but I would only like to do this if necessary. Thank You!

    Sincerely, Jakeinc

    Monday, November 11, 2013 3:06 PM
  • Hi Jakeinc,

    I suggest you could try the sample: http://code.msdn.microsoft.com/windowsapps/Print-Sample-c544cce6. In sixth scenario, print the image to the whole page is what you need.

    If still some error occurs, I'm willing to help.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, November 12, 2013 2:22 AM
    Moderator
  • Thanks. As of right now, I have copied the code. My problem is that I do not know what to put in PreparePrintContent(). In the example the method is blank. What do you think should be in the method.

    Sincerely, Jakeinc

    Saturday, November 16, 2013 5:01 AM
  • Hi Jakeinc,

    PreparePrintContent() is a virtual method, and could be override, if you take a look at scenario 1 to 5, you will able to see the override method like below, it could be used to manage the layout of the print stuff, such as adding the header, but in scenario 6 there is nothing to do with the image, that's why the method leave blank.

            protected override void PreparePrintContent()
            {
                if (firstPage == null)
                {
                    firstPage = new ScenarioOutput1();
                    StackPanel header = (StackPanel)firstPage.FindName("header");
                    header.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
    
                // Add the (newley created) page to the printing root which is part of the visual tree and force it to go
                // through layout so that the linked containers correctly distribute the content inside them.
                PrintingRoot.Children.Add(firstPage);
                PrintingRoot.InvalidateMeasure();
                PrintingRoot.UpdateLayout();
            }
    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Jamles HezModerator Friday, November 22, 2013 9:28 AM
    • Marked as answer by Jakeinc Friday, November 22, 2013 7:46 PM
    • Unmarked as answer by Jakeinc Saturday, November 23, 2013 6:30 PM
    • Marked as answer by Jakeinc Saturday, November 23, 2013 9:11 PM
    Tuesday, November 19, 2013 2:05 AM
    Moderator