locked
Image not included in my PrintDocument

    Question

  • Why are images are being excluded from my print document?

    I create a print document from an existing XAML page.  The document contains an image followed by a grid which contains various textblocks.  The grid and textblocks are printed but the image is being excluded.

    XAML (JournalPrint.xaml)

    <Page ... x:Name="PrintArea" >
    ... <Grid Background="Transparent" VerticalAlignment="Top"  HorizontalAlignment="Left" >
            <StackPanel Margin="60,60,40,40">           
                <Image Height="60" Margin="0" Width="600" Source="ms-appx:///Assets/banner.png" />           
                <Grid Background="Transparent" Height="40" Margin="0,10,0,0" >
                    ...
                </Grid>
                <ItemsControl x:Name="listview" ItemsSource="{Binding Path=sortedItems}" ItemTemplateSelector="{StaticResource JournalItemTemplateSelector}" />
            </StackPanel>
        </Grid>
    </Page>

    Code Behind doing the printing

    void OnGetPreviewPage(object sender, GetPreviewPageEventArgs args){
                this.printDocument.SetPreviewPageCount(printNbrOfPages, PreviewPageCountType.Final);
                // The framework element is the XAML page "JournalPrint".
                FrameworkElement page = new Views.JournalPrint(sortedItems, datepicker.Date, args.PageNumber, printLnesPerPage);
                Page printPage = (Page)page.FindName("PrintArea");           
                this.printDocument.SetPreviewPage(args.PageNumber, printPage);
            }

    Friday, June 27, 2014 9:53 AM

Answers

  • You're right - only images that are added in the calling page can have images.  I believe this is because the image control can only be used on the UI thread, which the print document is not running on.  You may want to try adding the content of the page to the current page, but off-screen, and adding that content to the print document.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 30, 2014 6:04 PM
    Moderator

All replies

  • Do you have a whole project I can work with? Please upload to OneDrive and paste a link here.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, June 27, 2014 7:47 PM
    Moderator
  • Here a test project which reproduces the problem: 

    onedrive.live.com/redir?resid=A8AC2DA03A31F506%21107
    (I'm having problems verifying my user.  Please add https:// to the link)

    The image "banner.png" is excluded from the print preview and the printed

    document even though the image is in the printed area.

    Saturday, June 28, 2014 9:32 AM
  • I did some more testing and have come to the following conclusions:

      • Only the page currently shown on the screen can be correctly used for the print document.  Not a second page which was supposed to be the print layout.
      • Adding a "canvas" dynamically to the print document does not work.  The canvas has to be shown on the screen.

    I assume this all has to do with the "pageView".  What I don't understand is why it only effects images and not text.

Sunday, June 29, 2014 1:13 PM
  • You're right - only images that are added in the calling page can have images.  I believe this is because the image control can only be used on the UI thread, which the print document is not running on.  You may want to try adding the content of the page to the current page, but off-screen, and adding that content to the print document.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 30, 2014 6:04 PM
    Moderator