Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Print a Diagram (Read 7646 times)
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Print a Diagram
Dec 20th, 2012 at 2:48pm
Print Post  
Hi Stoyo,
I am using version 2.3.0.16766 of the silverlight mindfusion controls. can you please suggest or point me in a direction that will help me print my diagram.
thanks, Don Almeida
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print a Diagram
Reply #1 - Dec 20th, 2012 at 3:32pm
Print Post  
Hi Don,

Call the Diagram.Print() method.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Print a Diagram
Reply #2 - Dec 20th, 2012 at 4:05pm
Print Post  
private void PrintCurrentDiagram()
        {
            this.currentDiagram.Print();
        }
I have this code that is called when the user hits the print toolbar button. this code throws exception "Dialogs must be user-initiated".
Am I missing something?
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print a Diagram
Reply #3 - Dec 20th, 2012 at 5:01pm
Print Post  
This is a Silverlight security feature, from MSDN: "For security purposes, if a Silverlight application is a sandboxed application, file and print dialog boxes must be user-initiated. This means you must show them from a user-initiated action, such as the click event handler for a button. If you attempt to show a dialog box from non-user initiated code, a SecurityException will occur. "

It should work if you call Print from a click handler of standard Silverlight controls. If you are using a third party UI library, you should discuss that with its developer; probably they are raising the event from outside of Silverlight's user events context (e.g. from a thread or timer instead of mouse click). Also check if you don't have two click handlers as here:
http://stackoverflow.com/questions/4113612/another-knack-on-the-dialogs-must-be-...
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Print a Diagram
Reply #4 - Dec 20th, 2012 at 11:01pm
Print Post  
Thanks, I was doing some other stuff in the print toolbar click. I commented that code and the exception went away. the print went through. There was a countup saying printing 1,2,3,4, of 1. I thought that was odd. the counts were not right. Then I went to the printer. I found one page and it only had a name on top. It had the name on top and page 4. but no diagram. the rest of the page was blank.
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print a Diagram
Reply #5 - Dec 21st, 2012 at 2:20pm
Print Post  
We were able to reproduce this, but it looks like some problem in Silverlight printing system. Testing this in the Anchors sample project, the control's PrintPage handler sets HasMorePages = false when on the first page since it fits all nodes, but Silverlight raises PrintPage several more times. The strange thing is, the same code works as expected in the Tutorial3 sample, where the nodes are all rectangular. So our developers' suspicion at this time is that the ovals and diagonal lines from the Anchors sample lead to some internal exception in Silverilght where HasMorePages is disregarded, and it continues raising PrintPage. Are there any nonrectangular shapes in the diagram you were trying to print?

Apparently Silverlight 5 printing was redesigned to send postscript instead of pre-rendered bitmaps to printers, and that might have something to do with this problem (http://10rem.net/blog/2011/06/11/silverlight-5-vector-and-bitmap-printing-for-re...). We'll try to force bitmap printing via the PrinterFallbackSettings class mentioned in the article to see if it helps.
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Print a Diagram
Reply #6 - Dec 21st, 2012 at 8:28pm
Print Post  
Appriciate looking into this Stoyo.
Happy holidays.
  

Don Almeida.
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Print a Diagram
Reply #7 - Dec 31st, 2012 at 5:54pm
Print Post  
Is there anything I need to do on my side or should I wait for an update from your side.

thanks,
Don Almeida.
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Print a Diagram
Reply #8 - Jan 2nd, 2013 at 9:31am
Print Post  
You could print a simplified copy of the diagram for the time being:

Code
Select All
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
	var copy = new Diagram();
	foreach (ShapeNode node in diagram.Nodes)
	{
		var border = new Border();
		border.BorderBrush = Brushes.Black;
		border.BorderThickness = new Thickness(1);
		var text = new TextBlock();
		text.Text = node.Text;
		border.Child = text;
		var replacement = new ControlNode(copy, border);
		replacement.Bounds = node.Bounds;
		copy.Nodes.Add(replacement);
	}
	foreach (DiagramLink link in diagram.Links)
	{
		var orgIndex = diagram.Nodes.IndexOf(link.Origin);
		var dstIndex = diagram.Nodes.IndexOf(link.Destination);
		copy.Factory.CreateDiagramLink(
			copy.Nodes[orgIndex], copy.Nodes[dstIndex]);
	}
	copy.Print();
} 



It appears that some element of ShapeNodes breaks the Silverlight 5 printing system, but we don't know yet which one exactly.

I hope that help,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint