How does 'Print' 'PrintPreview' works?

Hi,

I have two diagrams with diferent set of nodes & links:

  1. x diagram
  2. y diagram

Now I want to first show print preview & then print in the way, that y diagram should be available on each page & correspondingly x diagram’s object based on location.

How can I implement it using Goxam?

I implemented this requirement using GoDiagram as:

protected

override void PrintDecoration(Graphics g, PrintPageEventArgs e, int hpnum, int hpmax, int vpnum, int vpmax)

{

String msg = "";

msg =

Program.oGRM.GetStringFromResource("MF_ROUTE") + PSCreateGraph.PSMainFrm.SelectedRteFilter + "\n" +

Program.oGRM.GetStringFromResource("MF_PATTERN") + PSCreateGraph.PSMainFrm.SelectedPtFilter;

Font font = Properties.Settings.Default.Font;

SizeF size = g.MeasureString(msg, font);

PointF pt = new PointF(e.MarginBounds.X, e.MarginBounds.Y + e.MarginBounds.Height);

g.DrawString(msg, font,

Brushes.Blue, pt);

msg = (hpnum + 1).ToString() +

"/" + hpmax.ToString();

size = g.MeasureString(msg, font);

pt =

new PointF(e.MarginBounds.X + e.MarginBounds.Width / 2 - size.Width / 2,

e.MarginBounds.Y + e.MarginBounds.Height);

g.DrawString(msg, font,

Brushes.Blue, pt);

msg = System.Windows.Forms.

SystemInformation.UserName + "\n" + System.DateTime.Today.ToShortDateString();

size = g.MeasureString(msg, font);

pt =

new PointF(e.MarginBounds.X + e.MarginBounds.Width - size.Width,

e.MarginBounds.Y + e.MarginBounds.Height);

g.DrawString(msg, font,

Brushes.Blue, pt);

GraphicsContainer before = g.BeginContainer(); // save Graphics state

GoView _oYAxisView = PSCreateGraph.YAxisView; // get the GoView to be same while printed on each page

RectangleF pYAxisBounds = new RectangleF(_oYAxisView.DocumentTopLeft, _oYAxisView.DocExtentSize);

// draw into left margin, but not into top-left corner of page

// NB: the palette's Width needs to fit into the margin, otherwise it will overlap with the main view

g.TranslateTransform(

Math.Max(0, e.MarginBounds.X - pYAxisBounds.Width), e.MarginBounds.Y);

g.ScaleTransform(PrintScale, PrintScale);

// draw at same scale as the rest of the view

g.TranslateTransform(pYAxisBounds.X, pYAxisBounds.Y);

// normalize palette's PrintDocumentTopLeft

foreach (GoLayer oLayer in _oYAxisView.Layers) // draw each palette's document's layer

{

if (oLayer.Identifier.ToString() == "YAxisLabelLayer")

{

oLayer.Paint(g, _oYAxisView, pYAxisBounds);

Pen objPen = new Pen(Color.Black, 1.0F);

g.DrawLine(objPen,

new PointF(pYAxisBounds.Width, pYAxisBounds.Top), new PointF(pYAxisBounds.Width, pYAxisBounds.Top + pYAxisBounds.Height));

break;

}

}

g.EndContainer(before);

// restore Graphics state, so that this view will print normally

}

So are you saying that you want to print part of both diagrams on each page?
Does this include multiple pages in both the X and the Y axes?
That does not sound simple to implement.

Hi,

Yes, Y diagram (Left side) should print on each page, which would be same in reference to multiple pages of X diagram (right side).There could be multiple pages on X diagram, but only one same page on Y diagram.

I have already implemented this requirement, but using GoWin->GoDiagram library & already provided you the code.

Like:

Y diagram (Left side) : Only nodes with text block
X diagram (Right side): Set of nodes & links. Multiple page are possible based on location.X property of nodes & Points property of link.

I would try using the PrintManager.BackgroundTemplate to display your “Y diagram”, and let the “X diagram” print normally for however many pages are needed given reduced space on each page as specified by the PrintManager.Margin property.

This does mean that you may need to generate the BackgroundTemplate dynamically so that it has the text positioned at the places that you care about, just as you do in the “Y diagram” itself.

Hi,

Thanks for your previous reply.

Please provide me sample code as soon as you imlement this requirement.

Thanks

My previous reply suggested the best way for you to implement this without any delay.

Hi,

Can you also implement it, as you already aware of all features?

Yes, but not at this time. Sorry, things are pretty busy. I suppose if we did some consulting work for you I might be able to arrange for someone to create a sample for you.

Hi,

I tried, but not able to do it. It’s even not availabe in the samples & not in ‘GoXamIntro.pdf’.

I have to implement this requirement in POC, which I am preparing.

Based on the coverage of all existing functionalities, which are already implemneted using GoDiagram, my manager would decide to purchase license(GoXam.Silverlight component) or not.

So please do the needful in this regard, as it’s urgent.

Hi,

Is there any progress in this regard?

I suggest you experiment with PrintManager.BackgroundTemplate and .Margin. Are you able to show anything using that mechanism?

Hi,

No. I am not able to use

PrintManager.BackgroundTemplate

PrintManager.Margin

How can I use them to fulfil my requirement?

Can you provide me small sample code?

There’s an example of PrintManager.ForegroundTemplate in GoXamIntro.

Hi

But I am not able to use that example to implement my requirement, as I have to dynmically create fixed & same ‘yDiagram’ on each page & xDiagram as it is withing some predefined bounds.

How can I proceed?

Hi,

My evaluation of GoSilverlight is close to end. I am happy with your team's suppport.

But still printing task (according to my requirement), which is currently under your evaluation.

As soon as I implement it, I will show POC to my manager for his final decision.

So please do the needful in this regard as soon as possible, so that I can finalize it.

Thanks

I’m trying to help you implement your requirement. Were you able to add a test node or two to the PrintManager.BackgroundTemplate and change the PrintManager.Margin to be able to get the overall effect that you want? If so, the only issue is how to generate the template dynamically based on the contents of your “yDiagram”. If not, then maybe some other approach is needed.

Hi,

I tried to draw a textblock in foregroud templete of PrintManager, as same as mentioned in ‘GoXamIntro.pdf’, but textblock was missing in the output from the printer.

Please refer the code:

I triggered printing in .cs file on click event of a button using

Diagram.PrintManager.Print();

.xaml code:<

DataTemplate x:Key="PrintYDiagramTemplate">

<go:SpotPanel>

<TextBlock Text="Hello" FontSize="20"

go:SpotPanel.Spot="MiddleTop" go:SpotPanel.Alignment="MiddleBottom" />

</go:SpotPanel>

</DataTemplate>

<

go:Diagram.PrintManager>

<go:PrintManager ForegroundTemplate="{StaticResource PrintYDiagramTemplate}"

Margin="30 70 30 70" />

</go:Diagram.PrintManager>

OK, here’s a complete application that I think demonstrates one way of addressing your printing issue. You will need to fiddle with the numbers for your application, to get things lined up or spaced the way you want.

<!-- Copyright © Northwoods Software Corporation, 2008-2012. All Rights Reserved. --> <UserControl x:Class="SilverlightApplication1.MainPage" xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation" target="_blank" rel="nofollow">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>" xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml" target="_blank" rel="nofollow">http://schemas.microsoft.com/winfx/2006/xaml</a>" xmlns:go="<a href="http://schemas.nwoods.com/GoXam" target="_blank" rel="nofollow">http://schemas.nwoods.com/GoXam</a>" xmlns:local="clr-namespace:SilverlightApplication1"> <UserControl.Resources> <go:DataTemplateDictionary x:Key="DTD"> <DataTemplate x:Key=""> <Border Background="LightBlue" go:Node.Location="{Binding Path=Data.Location}" go:Node.LocationSpot="Center"> <TextBlock Text="{Binding Path=Data.Key}" Margin="5" /> </Border> </DataTemplate> <DataTemplate x:Key="Line"> <Line Stroke="Gray" X1="0" Y1="0" X2="1000" Y2="0" go:Part.LayerName="Background" go:Node.Location="{Binding Path=Data.Location}" /> </DataTemplate> <DataTemplate x:Key="Header"> <TextBlock Text="{Binding Path=Data.Key}" go:Node.Location="{Binding Path=Data.Location}" go:Node.LocationSpot="Center" /> </DataTemplate> </go:DataTemplateDictionary> </UserControl.Resources> <StackPanel> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <go:Diagram x:Name="myHeaderDiagram" Grid.Column="0" Padding="15" Width="60" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" NodeTemplateDictionary="{StaticResource DTD}" IsReadOnly="True"> </go:Diagram> <go:Diagram x:Name="myDetailsDiagram" Grid.Column="1" Padding="10" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" NodeTemplateDictionary="{StaticResource DTD}" IsReadOnly="True"> <go:Diagram.PrintManager> <local:DualPrintManager Tag="{Binding ElementName=myHeaderDiagram}" Margin="120 50 50 50"> </local:DualPrintManager> </go:Diagram.PrintManager> </go:Diagram> </Grid> <Button Content="Print" HorizontalAlignment="Left" Command="{Binding ElementName=myDetailsDiagram, Path=CommandHandler.PrintCommand}" /> </StackPanel> </UserControl>

/* Copyright © Northwoods Software Corporation, 2008-2012. All Rights Reserved. */ using System.Windows; using System.Windows.Controls; using System.Windows.Markup; using System.Windows.Printing; using Northwoods.GoXam; using Northwoods.GoXam.Model; namespace SilverlightApplication1 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); var hmodel = new GraphModel<SimpleData, string>(); hmodel.NodesSource = new SimpleData[] { new SimpleData { Key = "One", Category = "Header", Location = new Point(0, 0) }, new SimpleData { Key = "Two", Category = "Header", Location = new Point(0, 100) }, new SimpleData { Key = "Three", Category = "Header", Location = new Point(0, 200) } }; myHeaderDiagram.Model = hmodel; var dmodel = new GraphModel<SimpleData, string>(); dmodel.NodesSource = new SimpleData[] { new SimpleData { Category = "Line", Location = new Point(0, 0) }, new SimpleData { Category = "Line", Location = new Point(0, 100) }, new SimpleData { Category = "Line", Location = new Point(0, 200) }, new SimpleData { Key = "1a", Location = new Point(0, 0) }, new SimpleData { Key = "1b", Location = new Point(75, 0) }, new SimpleData { Key = "1c", Location = new Point(150, 0) }, new SimpleData { Key = "1d", Location = new Point(225, 0) }, new SimpleData { Key = "1e", Location = new Point(300, 0) }, new SimpleData { Key = "2a", Location = new Point(0, 100) }, new SimpleData { Key = "2b", Location = new Point(75, 100) }, new SimpleData { Key = "3a", Location = new Point(0, 200) }, new SimpleData { Key = "3b", Location = new Point(75, 200) }, new SimpleData { Key = "3c", Location = new Point(150, 200) }, new SimpleData { Key = "3d", Location = new Point(225, 200) }, new SimpleData { Key = "3e", Location = new Point(300, 200) }, new SimpleData { Key = "3f", Location = new Point(375, 200) }, new SimpleData { Key = "3g", Location = new Point(450, 200) }, new SimpleData { Key = "3h", Location = new Point(525, 200) }, new SimpleData { Key = "3i", Location = new Point(600, 200) }, new SimpleData { Key = "3j", Location = new Point(675, 200) }, new SimpleData { Key = "3k", Location = new Point(750, 200) } }; myDetailsDiagram.Model = dmodel; } } public class DualPrintManager : PrintManager { protected override void OnStarting(PrintPageEventArgs e) { var hdrdiag = this.Tag as Diagram; if (hdrdiag != null) { string tmpl = @"<DataTemplate xmlns=""<a href="http://schemas.microsoft.com/client/2007" target="_blank" rel="nofollow">http://schemas.microsoft.com/client/2007</a>"">"; tmpl += @"<Canvas>"; foreach (Node node in hdrdiag.Nodes) { var tb = (TextBlock)node.VisualElement; // make the text safe for XML var text = tb.Text; text = text.Replace("&", "&amp;"); text = text.Replace("<", "&lt;"); text = text.Replace(">", "&gt;"); tmpl += @"<TextBlock Text=""" + text + @""" Canvas.Left=""" + (node.Position.X - 60).ToString() + @""" Canvas.Top=""" + (node.Position.Y + 20).ToString() + @""" />"; } tmpl += @"</Canvas>"; tmpl += @"</DataTemplate>"; this.BackgroundTemplate = (DataTemplate)XamlReader.Load(tmpl); } base.OnStarting(e); } } public class SimpleData : GraphModelNodeData<string> { } }
I think you can take it from here.

Hi,

Thanks for your sample code. It worked as I expected to implement.