This is a migrated thread and some comments may be shown as answers.

print multiple diagrams in one batch

7 Answers 111 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
HDC
Top achievements
Rank 1
HDC asked on 22 Aug 2012, 11:24 AM
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

7 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 23 Aug 2012, 08:39 AM
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.

0
HDC
Top achievements
Rank 1
answered on 23 Aug 2012, 11:05 AM
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

0
Francois Vanderseypen
Top achievements
Rank 2
answered on 23 Aug 2012, 11:19 AM
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.
0
HDC
Top achievements
Rank 1
answered on 23 Aug 2012, 11:37 AM
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
0
HDC
Top achievements
Rank 1
answered on 23 Aug 2012, 11:50 AM
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
0
Francois Vanderseypen
Top achievements
Rank 2
answered on 23 Aug 2012, 12:08 PM
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.
0
HDC
Top achievements
Rank 1
answered on 23 Aug 2012, 12:57 PM
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
Tags
Diagram
Asked by
HDC
Top achievements
Rank 1
Answers by
Hristo
Telerik team
HDC
Top achievements
Rank 1
Francois Vanderseypen
Top achievements
Rank 2
Share this question
or