none
[UWP]How to print the InkCanvas stroke? RRS feed

Answers

  • Hey Javier Ra,

    As the message on GitHub so kindly tells you ... 
    1. Just compose a Bitmap image from ink-strokes
    2. and print it with Toolkit's PrintHelper.

        private async void Printer_Click(object sender, RoutedEventArgs e)
        {
            // Create a Bitmap from the strokes.
            var inkStream = new InMemoryRandomAccessStream();
            await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(inkStream.GetOutputStreamAt(0));
            var inkBitmap = new BitmapImage();
            await inkBitmap.SetSourceAsync(inkStream);
    
            // You need to adjust Margin to layout the image properly in the print-page. 
            var inkBounds = inkCanvas.InkPresenter.StrokeContainer.BoundingRect;
            var inkMargin = new Thickness(inkBounds.Left, inkBounds.Top, inkCanvas.ActualWidth - inkBounds.Right, inkCanvas.ActualHeight - inkBounds.Bottom);
    
            // Prepare Viewbox+Image to be printed.
            var inkViewbox = new Viewbox()
            {
                Child = new Image()
                {
                    Source = inkBitmap,
                    Margin = inkMargin
                },
                Width = inkCanvas.ActualWidth,
                Height = inkCanvas.ActualHeight
            };
    
            //Canvas canvas = new Canvas();
            _printHelper = new PrintHelper(PrintCanvas);
            //_printHelper.AddFrameworkElementToPrint(canvas);
            _printHelper.AddFrameworkElementToPrint(inkViewbox);
    
    
            _printHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
            _printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
    
            var printHelperOptions = new PrintHelperOptions();
            printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation);
            printHelperOptions.Orientation = PrintOrientation.Landscape;
    
            await _printHelper.ShowPrintUIAsync("printing InkPen", printHelperOptions);
        }

    • Marked as answer by Javier Ra Friday, March 8, 2019 8:30 AM
    • Edited by FEC-4RP Friday, March 8, 2019 1:36 PM
    Thursday, March 7, 2019 9:14 AM

All replies

  • Hi,

    You could try to use Print Helper from Windows Community Toolkit. This tool could help your to print the frameworkElement. So you could try to print the inkcanvas directly.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 28, 2019 7:22 AM
    Moderator
  • Hi:

    the photpPrintHelper would be missing if only using PrintHelper would require PagetoPrint

    Monday, January 28, 2019 8:38 PM
  • Hi,

    I could not fully understand your question. If you use Print Helper from Windows Community Toolkit. There is no photpPrintHelper. What is the photpPrintHelper  you mean?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 29, 2019 2:41 AM
    Moderator
  • Hi,

    For example in La App ColoringBook this PrintHelper.cs and PhotoPrinterHelper.cs , here you need PhotoPrinterHelper.cs or you can only do it with PrintHelper.cs.

    Wednesday, January 30, 2019 8:59 AM
  • Hi,

    The ColoringBook seems to have a different implementation compare to Print Helper of the Windows Community Toolkit. The Print Helper is just an extension that could used to directly print the framework element. If you wants to use that way, you could definitely do it.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 31, 2019 5:59 AM
    Moderator
  • pritnHelper.cs

    When I go to the Print button I put await printhelper. ShowprintUiAsync (); tells me failure ShwoPritnUiAsync.

    There is no argument that corresponds to the required formal parameter ' prinTaskName ' of PrintHelper. ShowPrintUiAsync (String, PrintHelperOptions, BOOL)

    Thursday, January 31, 2019 11:43 AM
  • Hi,

    Please refer this Print Helper document in my first reply. It mentions that “In addition, you can customize the printing dialog using the PrintHelperOptions class. To use it, create an instance of the class, add the options you'd like to display on the printing dialog and set the default options. Then, you can use it as a parameter in the PrintHelper class constructor to set them as the default for the instance, or send them as parameters to ShowPrintUIAsync to use them for a single print job. You can call ShowPrintUIAsync with a second parameter to determine that the list of controls to print should directly be taken from the content of the container passed to the PrintHelper constructor. In this mode you are responsible for the sizing and the layout."

    It explains why and how to use the PrintHelperOptions for the ShowPrintUiAsync  method.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 1, 2019 3:27 AM
    Moderator
  • Hi:

    I Have this problem here:

     private  async void Printer_Click(object sender, RoutedEventArgs e)
            {
    
              
                await Components.PrintHelper.ShowPrintUIAsync(printHelperOptions);
               
            }

    When I put printOptionsHelpers I point out no exite in the current context.
    • Edited by Javier Ra Friday, February 1, 2019 7:02 PM destacar
    Friday, February 1, 2019 7:01 PM
  • Hi,

    I checked the source code for PrintHelper.cs, it seems do not contains a method like ShowPrintUIAsync(PrintHelperOptions printHelperOptions). Is it a method that you defined yourself?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 4, 2019 2:44 AM
    Moderator
  • Hi, 

    This failure occurs in MainPage

    Monday, February 4, 2019 8:01 PM
  • Hi,

    It seems that you defined a ShowPrintUIAsync method yourself and use it in the mainpage? What's the printHelperOptions? How you define your own ShowPrintUIAsync method? What do you mean by When I put printOptionsHelpers I point out no exite in the current context, I could not understand it well. Could you please explain this with more details? What is the behavior you are getting and what's the behavior you want to get?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 5, 2019 6:50 AM
    Moderator
  • PrintHelperOption There is no current context
    Tuesday, February 5, 2019 6:21 PM
  • Hi,

    The printHelperOptions is a PrintHelperOptions object that you need to created yourself. You need to write your own printHelperOptions. 

    Another thing is that in the source code of PrintHelper.cs,  it seems do not contains a method like ShowPrintUIAsync(PrintHelperOptions printHelperOptions).  All the ShowPrintUIAsync method requires at least 2 parameter. Is the ShowPrintUIAsync you are using that defined by yourself?

    Best regards.

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 6, 2019 8:24 AM
    Moderator
  • windows.ToolkIt.UWp

    I like this here the Printhelepr.cs

    Wednesday, February 6, 2019 6:17 PM
  • Hi,

    So did the source code of PrintHelper.cs helps you to solve the problem? 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 7, 2019 3:10 AM
    Moderator
  • Hi:

    The problem is the Button_Click what is the PrinterHelper.cs is the same as the document.

    Thursday, February 7, 2019 4:28 PM
  • Hi,

    What do you mean by "The problem is the Button_Click what is the PrinterHelper.cs is the same as the document."?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 12, 2019 5:56 AM
    Moderator
  • hi:

    The problem the Print button is with the ShowPrintUIAsync.

    private async void printer_Click(object sender, RoutedEventArgs e)

    {

     await PrintHelper.showPrintUiAsync();

    }


    • Edited by Javier Ra Tuesday, February 12, 2019 2:12 PM mro information
    Tuesday, February 12, 2019 1:10 PM
  • Hi,

    The code you post is different from the code in your screen shot. What's the behavior you want to get and what's the behavior you are getting now?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 13, 2019 2:16 AM
    Moderator
  • Hi:

    When I put await Printhelper. ShowPrintUIAsync (), tells me failure in the ShowPrintUIAsync ()


    • Edited by Javier Ra Wednesday, February 13, 2019 10:49 AM error
    Wednesday, February 13, 2019 10:49 AM
  •   private  async void Printer_Click(object sender, RoutedEventArgs e)
            {
    
                await printHelper.ShowPrintUIAsync();
               
            }
    Failure: No overload the ShowPrintUIAsync method.
    Wednesday, February 13, 2019 7:30 PM
  • Hi,

    In the source code of PrintHelper.cs,  it seems do not contains a method like ShowPrintUIAsync().  All the ShowPrintUIAsync method requires at least 2 parameter. Is the ShowPrintUIAsync you are using that defined by yourself?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 18, 2019 5:04 AM
    Moderator
  • Hi:

    this problem : i am using Microsoft Community Tools


    • Edited by Javier Ra Wednesday, February 20, 2019 11:25 AM more information
    Wednesday, February 20, 2019 11:24 AM
  • I am using Windows Community Toolkit to print the stroke on the InkCanvas. The problem is that I get the Print wizard but I do not draw it in the InkCanvas.
    C#
    
     private  async void Printer_Click(object sender, RoutedEventArgs e)
            {
    
                Canvas canvas = new Canvas();
                _printHelper = new PrintHelper(PrintCanvas);
                _printHelper.AddFrameworkElementToPrint(canvas);
    
                
                _printHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
                _printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
    
    
                var printHelperOptions = new PrintHelperOptions();
                printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation);
                printHelperOptions.Orientation = PrintOrientation.Landscape;
    
                
    
                await _printHelper.ShowPrintUIAsync("printing InkPen", printHelperOptions);
              
            }
    
            
    
            private async void PrintHelper_OnPrintSucceeded()
            {
               _printHelper.Dispose();
                var dialog = new MessageDialog("Printing done.");
                await dialog.ShowAsync();
            }
    
            private async void PrintHelper_OnPrintFailed()
            {
                _printHelper.Dispose();
                var dialog = new MessageDialog("Printing failed");
                await dialog.ShowAsync();
            }
    xaml
       x:Class="InkPen.Views.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Style="{StaticResource PageStyle}"
        mc:Ignorable="d">
        <Grid
            x:Name="ContentArea"
            Margin="{StaticResource MediumLeftRightMargin}">
    
            <Grid.RowDefinitions>
                <RowDefinition Height="48"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <TextBlock x:Name="TitlePage"
                       x:Uid="Ink_Title"
                       Style="{StaticResource PageTitleStyle}"  Foreground="{ThemeResource SystemAccentColorDark1}"/>
    
    
            <Grid  Grid.Row="1" 
                Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
              
            <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <CommandBar
                    DefaultLabelPosition="Collapsed"
                    HorizontalAlignment="Left"
                    HorizontalContentAlignment="Left">
                    <CommandBar.Content>                    
                        <InkToolbar x:Name="toolbar" TargetInkCanvas="{x:Bind inkCanvas}">
                            <InkToolbarCustomToolButton
                                x:Uid="InkDraw_LassoSelectionButton"
                                Name="lassoSelectionButton"
                                Checked="LassoSelection_Checked"
                                Unchecked="LassoSelection_Unchecked">
                                <FontIcon
                                    FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                    Glyph="&#xEF20;" />
                            </InkToolbarCustomToolButton>
                            <InkToolbarCustomToggleButton
                                x:Uid="InkDrawPictureView_TouchInkingButton"
                                Name="touchInkingButton"
                                Checked="TouchInking_Checked"
                                Unchecked="TouchInking_Unchecked">
                                <FontIcon
                                    FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                    Glyph="&#xED5F;" />
                            </InkToolbarCustomToggleButton>
                            <InkToolbarCustomToggleButton
                                x:Uid="InkDrawPictureView_MouseInkingButton"                            
                                Name="mouseInkingButton"
                                Checked="MouseInking_Checked"
                                Unchecked="MouseInking_Unchecked">
                                <FontIcon
                                FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                Glyph="&#xE962;" />
                            </InkToolbarCustomToggleButton>
                        </InkToolbar>
                    </CommandBar.Content>
                    <AppBarSeparator />
                    <AppBarButton
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_ZoomInButton"
                        Icon="ZoomIn"
                        Click="ZoomIn_Click" />
                    <AppBarButton
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_ZoomOutButton"
                        Icon="ZoomOut"
                        Click="ZoomOut_Click" />
                    <AppBarSeparator/>
                    <AppBarButton
                        Name="CutButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_CutButton"
                        Icon="Cut"
                        Click="Cut_Click" />
                    <AppBarButton
                        Name="CopyButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_CopyButton"
                        Icon="Copy"
                        Click="Copy_Click" />
                    <AppBarButton
                        Name="PasteButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_PasteButton"
                        Icon="Paste"
                        Click="Paste_Click" />
                    <AppBarSeparator />
                    <AppBarButton
                        Name="UndoButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_UndoButton"
                        Icon="Undo"
                        Click="Undo_Click" />
                    <AppBarButton
                        Name="RedoButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_RedoButton"
                        Icon="Redo"
                        Click="Redo_Click" />
                    <AppBarSeparator/>
                    <AppBarButton
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_SelectorButton">
                        <AppBarButton.Icon>
                            <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE9E9;"/>
                        </AppBarButton.Icon>
                        <AppBarButton.Flyout>
                            <Flyout>
                                <StackPanel>
                                    <ToggleSwitch Name="GripBoard"  x:Uid="TG_Grip"
                                                  Toggled="ToggleGraph_Toggled"
                                                  ManipulationDelta="OnInkCanvasManipulationDelta"
                                                  ManipulationMode="Scale"
                                                  Tapped="OnGripBoardTapped"/>
    
                                            
    
    
                                </StackPanel>
    
                                
                            </Flyout>
                        </AppBarButton.Flyout>
                    </AppBarButton>
                        
                        
                    
                    <AppBarButton
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_LoadInkFileButton"
                        Icon="OpenFile"
                        Click="LoadInkFile_Click" />                   
                    <AppBarButton
                        Name="SaveInkFileButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_SaveInkFileButton"
                        Icon="Save"
                        Click="SaveInkFile_Click" />
                    <AppBarButton
                        Name="ExportAsImageButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_ExportAsImageButton"
                        Icon="Download"
                        Click="ExportAsImage_Click" />
                    <AppBarSeparator/>
                    <AppBarButton
                        Name="ClearAllButton"
                        IsEnabled="False"
                        BorderBrush="Transparent"
                        BorderThickness="0,0,0,0"
                        x:Uid="InkDraw_ClearAllButton"
                        Icon="Delete"
                        Click="ClearAll_Click" />
    
                    <AppBarButton
                        x:Name="PrinterButton"
                        x:Uid="Printer"
                        Icon="Print"
                        Click="Printer_Click"/>
    
                    <AppBarButton
                        x:Name="ShareButton"
                        x:Uid="Share"
                        Icon="Share"
                        Click="OnShare_Click"/>
    
                </CommandBar>
    
    
                <ScrollViewer
                    Name="canvasScroll"
                    Grid.Row="1"
                    Margin="8,0,8,0"
                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                    ScrollViewer.HorizontalScrollBarVisibility="Auto"
                    ZoomMode="Enabled">
    
                    <Viewbox x:Name="CanvasViewBox"
                             HorizontalAlignment="Center"
                             Stretch="Uniform"
                             VerticalAlignment="Center">
    
                    <Grid   Background="{StaticResource InkCanvasBackground}"
                              Width="{Binding ElementName=inkCanvas, Path=Width}"
                              Height="{Binding ElementName=inkCanvas, Path=Height}" >
    
    
                            <Canvas x:Name="PrintCanvas" Opacity="0"/>
    
    
                            <ctrls:GraphPaperUserControl
                                x:Name="graphPaper"
                                xmlns:ctrls="using:InkPen.UserControls" Visibility="Collapsed"/>
    
                                
    
                            <InkCanvas x:Name="inkCanvas"
                                   HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"/>
    
    
                        <Canvas x:Name="selectionCanvas"
                                Width="{Binding ElementName=inkCanvas, Path=Width}"
                                Height="{Binding ElementName=inkCanvas, Path=Height}"/>
    
                        <Image x:Name="MyImage"
                               IsHitTestVisible="False"
                               IsTapEnabled="False"/>
    
                    </Grid>
                    </Viewbox>
                </ScrollViewer>
               
            </Grid>
        </Grid>
    </Page>
    


    Monday, February 25, 2019 2:36 PM
  • Hi,

    What do you mean by "The problem is that I get the Print wizard but I do not draw it in the InkCanvas."? Does the preview show an empty page?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 26, 2019 3:16 AM
    Moderator
  • Hi:

    Yes, When I press the button exits the blank wizard but does not leave the drawing in the InkCanvas.


    • Edited by Javier Ra Tuesday, February 26, 2019 9:01 AM mistake
    Tuesday, February 26, 2019 8:53 AM
  • Hi ,

    I suggest that you might need to open a support ticket for this. Please contact our paid phone support at MS Support. You will get 1:1 support on that. Please kindly note that your support ticket will be free if it is Microsoft's issue.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 27, 2019 7:35 AM
    Moderator
  • Hello :

    On GITHUB tells ME that print directly InkCanvas drawing cannot be printed.

    Based on how the InkCanvas works, you won't be able to print the drawings using the toolkit's PrintHelper directly.

    To get the drawings from the InkCanvas, you can use the InkPresenter property, which handles the drawings themselves. From there, you can use the StrokeContainer, which allows you to save the strokes of the drawing with the SaveAsync method. Using an InkPersistenceFormat of GifWithEmbeddedIsf, you'll get the drawing in GIF format inside an IOutputStream.

    Once you have the GIF in a stream, you can add it to the view with an Image control, which you can then add to the printing elements and print it.

    Thursday, February 28, 2019 6:22 PM
  • how can I print the drawing of the inkCanvas if PrintHelper does not serve to take out the drawing when it comes out the wizard does not show anything of what has been done in InKCanvas.

    What I want to do is to print the drawing of the InkCanvas

    Depending on how the InkCanvas works, you will not be able to print the drawings using the PrintHelper of the toolkit directly.
    To get the drawings of the InkCanvas, you can use the InkPresenter property, which is in charge of the drawings. From there, you can use the StrokeContainer, which allows you to save the strokes of the drawing with the SaveAsync method. With a InkPersistenceFormat of GIFWITHEMBEDDEDISF, you will get the drawing in GIF format within a IOutputStream.
    Once you have GIF in a stream, you can add it to the view with an Image control, which you can then add to the print items and print it.
    Close the problem as the problem is not related to the toolkit

    Wednesday, March 6, 2019 6:11 PM
  • Hi ,

    I suggest that you might need to open a support ticket for this. Please contact our paid phone support at MS Support. You will get 1:1 support on that. Please kindly note that your support ticket will be free if it is Microsoft's issue.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 7, 2019 1:56 AM
    Moderator
  • Hey Javier Ra,

    As the message on GitHub so kindly tells you ... 
    1. Just compose a Bitmap image from ink-strokes
    2. and print it with Toolkit's PrintHelper.

        private async void Printer_Click(object sender, RoutedEventArgs e)
        {
            // Create a Bitmap from the strokes.
            var inkStream = new InMemoryRandomAccessStream();
            await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(inkStream.GetOutputStreamAt(0));
            var inkBitmap = new BitmapImage();
            await inkBitmap.SetSourceAsync(inkStream);
    
            // You need to adjust Margin to layout the image properly in the print-page. 
            var inkBounds = inkCanvas.InkPresenter.StrokeContainer.BoundingRect;
            var inkMargin = new Thickness(inkBounds.Left, inkBounds.Top, inkCanvas.ActualWidth - inkBounds.Right, inkCanvas.ActualHeight - inkBounds.Bottom);
    
            // Prepare Viewbox+Image to be printed.
            var inkViewbox = new Viewbox()
            {
                Child = new Image()
                {
                    Source = inkBitmap,
                    Margin = inkMargin
                },
                Width = inkCanvas.ActualWidth,
                Height = inkCanvas.ActualHeight
            };
    
            //Canvas canvas = new Canvas();
            _printHelper = new PrintHelper(PrintCanvas);
            //_printHelper.AddFrameworkElementToPrint(canvas);
            _printHelper.AddFrameworkElementToPrint(inkViewbox);
    
    
            _printHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
            _printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
    
            var printHelperOptions = new PrintHelperOptions();
            printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation);
            printHelperOptions.Orientation = PrintOrientation.Landscape;
    
            await _printHelper.ShowPrintUIAsync("printing InkPen", printHelperOptions);
        }

    • Marked as answer by Javier Ra Friday, March 8, 2019 8:30 AM
    • Edited by FEC-4RP Friday, March 8, 2019 1:36 PM
    Thursday, March 7, 2019 9:14 AM
  • Hi:

    The assistant will the stroke of InkCanvas but on the desktop PC tells me the assistant 0 documents instead the laptop tells me printing sending but it takes to print

    Friday, March 8, 2019 9:47 AM
  • umm?

    Print notification icon with "0 document(s) pending ..." remains on the screen for a while after printing a document. That's a right behavior of Windows10. It will automatically disappear in a minute or so.

    If it seems to take too much (or otherwise infinitely) to begin printing the document on your laptop, the printer device might not be working correctly. Try trouble-shooting by yourself (check: connection, power-supply, driver version, configuration, etc.). If the built-in "Print to PDF" works properly anyway, your app would be ok.

    Friday, March 8, 2019 1:18 PM
  • Hi:

    When I give to print the printing box I get pages N/D, in the state puts me printing

    Saturday, March 9, 2019 6:48 PM
  • ... Sorry, I can't understand at all what the problem you are currently having is. Please explain more in detail, using code-snippets, screenshots and/or tons of text. Or otherwise ask MS-support for realtime help as Roy does suggest.
    Sunday, March 10, 2019 11:41 PM
  • where it says "Pagi" it says N/D, because it comes out N/D and does not come out page 1
    Monday, March 11, 2019 2:02 PM
  • I see, but I have no idea why it displays N/D. It might be due to some problem in printer's side. To confirm the device is working correctly, try printing out something else in another UWP app (such as Photo app) anyway. If you can't print out anything with that printer, just consult HP-support.


    In case print-funciton doesn't seem to work only in your app, you might need to configure some more options in the print dialog. By enabling more items in PrintHelperOptions, try printing ink-strokes with various configuration-combinations.

           var printHelperOptions = new PrintHelperOptions();
    
           printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Copies); 
           printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation); 
           printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.MediaSize); 
           printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Collation); 
           printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Duplex); 
    
           printHelperOptions.Orientation = PrintOrientation.Landscape;
    
           await _printHelper.ShowPrintUIAsync("printing InkPen", printHelperOptions);
    • Edited by FEC-4RP Wednesday, March 13, 2019 4:14 PM
    Tuesday, March 12, 2019 12:54 AM
  • Hello:

    I've been testing from the laptop connecting WiFi to the printer, print the image I put in the forum but a test, the app with InkCanvas not take it out from laptop and desktop can a bug Windows. Community. Toolkit

    Tuesday, March 12, 2019 5:59 PM
  • From another app with InkCanvas that I downloaded from the store to try from the laptop to the printer that has WiFi prints what it does in the InkCanvas
    Tuesday, March 12, 2019 6:07 PM
  • Hi

    It seems the trouble (Page=N/D) is due to Toolkit's bug as you expect. In PrintHelper.CreatePrintPreviewPages() function, ClearPageCache()-call asynchonously clears _printPreviewPages that is already filled with new pages. Therefore, no page is to be sent to the printer. 

    However by good luck, it seems that you can avoid that execution path by specifying _directPrint=true. So take this workaround anyway.

            private async void Printer_Click(object sender, RoutedEventArgs e)
            {
                // Create a Bitmap from the strokes.
                var inkStream = new InMemoryRandomAccessStream();
                await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(inkStream.GetOutputStreamAt(0));
                var inkBitmap = new BitmapImage();
                await inkBitmap.SetSourceAsync(inkStream);
    
                // Adjust Margin to layout the image properly in the print-page. 
                var inkBounds = inkCanvas.InkPresenter.StrokeContainer.BoundingRect;
                var inkMargin = new Thickness(inkBounds.Left, inkBounds.Top, inkCanvas.ActualWidth - inkBounds.Right, inkCanvas.ActualHeight - inkBounds.Bottom);
    
                // Prepare Viewbox+Image to be printed.
                var inkViewbox = new Viewbox()
                {
                    Child = new Image()
                    {
                        Source = inkBitmap,
                        Margin = inkMargin
                    },
                    Width = inkCanvas.ActualWidth,
                    Height = inkCanvas.ActualHeight
                };
    
                PrintCanvas.Children.Clear();
                PrintCanvas.Children.Add(inkViewbox);
    
                //Canvas canvas = new Canvas();
                _printHelper = new PrintHelper(PrintCanvas);
                //_printHelper.AddFrameworkElementToPrint(canvas);
                //_printHelper.AddFrameworkElementToPrint(inkViewbox);
    
                _printHelper.OnPrintFailed += PrintHelper_OnPrintFailed;
                _printHelper.OnPrintSucceeded += PrintHelper_OnPrintSucceeded;
    
                var printHelperOptions = new PrintHelperOptions();
                printHelperOptions.AddDisplayOption(StandardPrintTaskOptions.Orientation);
                printHelperOptions.Orientation = PrintOrientation.Landscape;
    
                await _printHelper.ShowPrintUIAsync("printing InkPen", printHelperOptions, true);
            }
    • Edited by FEC-4RP Wednesday, March 13, 2019 4:37 PM
    Wednesday, March 13, 2019 4:12 PM
  • hello:

    Already works the impression what is done is to change the version 5.0 by the version 4.0 of Community. Toolkit.

    Thank you.

    Wednesday, March 13, 2019 5:44 PM