print multiple diagrams in one batch

8 posts, 0 answers
  1. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 22 Aug 2012 Link to this post

    Hi,

    Suppose i have a series of diagrams, how would i go about printing all of these diagrams without having to show them visually to the user?

    Best Regards,

    Peter
  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 23 Aug 2012 Link to this post

    Hi,

    In Silverlight you are forced to open the system Print Dialog Window. This is done with security considerations.
    So even if you do not show the diagrams to the user, the print dialog will pop up and ask for confirmation.

    Could you provide us a bit more details about your solution and requirements?

    Greetings,
    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 23 Aug 2012 Link to this post

    Hi Hristo,

    I don't mind for the print dialog... that is even exactly what i would want.

    This is my problem:

    I'm using the diagram component as a way to create a powerpoint-like application. I have a number of "slides", which i display in miniature and when the user clicks a slide, i use a centrally placed diagram component to allow the user to edit the selected "slide".

    This has all worked wonderfully well so far!

    The challenge at hand now is... how do i print this "presentation" without having to visually load them in one by one before print or without requiring them to print them one by one.

    Best Regards,

    Peter

  5. Francois Vanderseypen
    Francois Vanderseypen avatar
    46 posts
    Member since:
    Oct 2009

    Posted 23 Aug 2012 Link to this post

    Peter, as it stands now I don't think you can use the supplied print mechanism of RadDiagram. Whether you use MVVM with one instance of a control or you have multiple controls (across tabs e.g.) the print implementation will only collect one diagram at a time.
    So, for now the best option is to create a custom print-dialog (and paginator, see this article for instance). This is not as difficult as it might seem at first and it allows you to have a much deeper control (parametrization) over the output.

    Currently the feature you need is not in the planning but thanks for letting us know how you're using RadDiagram! You can always post a feature request in PITS.

    Fr.
  6. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 23 Aug 2012 Link to this post

    Hi Francois,

    Thanks for the lightning-fast-reaction. I can see how this could work, thanks for the tip!

    Would it be at all possible to help me on the way with the "OnRender" method?
     
    How would i go about loading the slide in there?
     
    Can i use the diagram for that somehow or do i need to really "draw" on the page?

    It seems to me that the most likely approach would be to load the slide in a hidden diagram, export it to an image and place it on the document, then load the next slide into the diagram, export it to an image and place it on the document.Would this work you think?

    Best Regards,

    Peter
  7. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 23 Aug 2012 Link to this post

    Hi Francois,

    This article is for WPF, and there seems to be no Silverlight counterpart i can find.

    Can you help me out here?

    Best Regards,

    Peter
  8. Francois Vanderseypen
    Francois Vanderseypen avatar
    46 posts
    Member since:
    Oct 2009

    Posted 23 Aug 2012 Link to this post

    Peter, if your app is really PowerPoint-like then it means you have a simplification since there is no page-splitting (splitting a diagram or slide across multiple pages). The printing is indeed just a rendering method like the old Winform rendering. RadDiagram also exposes methods to export/save images so I'd think it's just a matter of taking some things together. Whether in-memory istantiation of RadDiagram, rendering, image-saving, image insertion in the printing page...all works, if your environment is Silverlight then I worry however that there are some hidden tricks/issues related to security.
    Give it a try, if you're stuck, ping me here.

    Fr.
  9. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 23 Aug 2012 Link to this post

    Hi Francois,

    I agree, it will most definately be a lot simpeler then powerpoint and my ambition is not to mimic powerpoint in Silverlight. My application will offer certain things specific to the project that is very difficult to achieve in powerpoint and it will avoid having a dependency on powerpoint itself.

    That being said, i have cooked up following code for who ever may be interested in accomplishing a similar task:

    On the xaml side:

    <UserControl x:Class="RadControlsSilverlightApp2.MainPage"
            mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="100"></RowDefinition>
            </Grid.RowDefinitions>
            <telerik:RadDiagram x:Name="MyDiagram" Grid.Row="0"  Height="0" Width="0">          
            </telerik:RadDiagram>
            <Button Content="Pr!nt" Click="Button_Click" Grid.Row="1"></Button>
        </Grid>
    </UserControl>

    On codebehind side
    bool printmoreslide = true;
     
    private void Button_Click(object sender, RoutedEventArgs e)
    {
      PrintDocument pd = new PrintDocument();
      pd.PrintPage += (object sender2, PrintPageEventArgs e2) =>
      {
        //Add a testshape
        RadDiagramShape shapeCloud = new RadDiagramShape()
        {
          Width = 180,
          Height = 100,
          Position = new Point() { X = 100, Y = 100 },
          Content = "Cloud"
        };
        shapeCloud.Geometry = ShapeFactory.GetShapeGeometry(CommonShapeType.CloudShape);
        MyDiagram.AddShape(shapeCloud);
     
        //export it to a picture
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        MyDiagram.ExportToImage(ms);
     
        //put the picture on the page so it becomes the content of the page
        BitmapImage bi = new BitmapImage();
        bi.SetSource(ms);
        Image image = new Image() { Source = bi };
        e2.PageVisual = image;
     
        //clear the diagram
        MyDiagram.Clear();
     
        //should print the diagram twice, simulating printing multiple slides
        e2.HasMorePages = printmoreslide;
        printmoreslide = false;
      };
      pd.Print("blabla");
    }

    It is incredibily primitive, and it doesn't give a particularly nice output either, as the cloud will be as big as the page, but this is related to the export features combined with the features of the PrintDocument and i will have to study those things next, but the key thing is that it works.

    Best Regards and thanks for putting me on my way,

    Peter
Back to Top
DevCraft banner