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

[Solved] Silverlight RadGrid Printing

0 Answers 42 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nambi
Top achievements
Rank 1
Nambi asked on 03 Apr 2013, 06:16 AM
Hello All,

I have 4 RadPane groups inside the stack panel. Each radpane group has different controls assigned. The first and last Radpanegroup holds RADGRID and second one holds Bullet Chart and third one holds Score chart. I want to print first two rad pane group on single page and third radpane on second page and the fourth radpane on third page. Please let me know how to achieve this in Silverlight printing. Current Code used is shown below.

 

private void onExecutePrintCommand(StackPanel p)

 

{

PrintDocument pd =

new PrintDocument();

 

 

double originalWidth = p.Width;

 

 

double originalHeight = p.Height;

 

 

List<ExtendedImage> images = new List<ExtendedImage>();

 

ExtendedImage ei;

 

int _currentPage;

 

ei = ImageExtensions.ToImage(p);

//stkPanel - Control that you want to print

 

_currentPage = 0;

Viewbox box =

new Viewbox();

 

pd.PrintPage += (s, e) =>

{

 

int printableAreaHeight = Convert.ToInt32(e.PrintableArea.Height);

 

 

int printableAreaWidth = Convert.ToInt32(e.PrintableArea.Width);

 

 

int ActualImageHeight = ei.PixelHeight;

 

 

int ActualImageWidth = ei.PixelWidth;

 

 

int NoOfPages = (ActualImageHeight / printableAreaHeight);

 

 

if ((ActualImageHeight % printableAreaHeight) > 0)

 

NoOfPages += 1;

images =

new List<ExtendedImage>();

 

ImageTools.Rectangle rt;

 

int xCoordinate = 0;

 

 

int yCoordinate = 0;

 

 

int rectangleHeight = 0;

 

 

for (int i = 0; i < NoOfPages; i++)

 

{

 

if (i > 0)

 

{

yCoordinate = printableAreaHeight * i;

}

 

if ((i + 1) == NoOfPages)

 

{

 

if ((ActualImageHeight % printableAreaHeight) > 0)

 

rectangleHeight = (ActualImageHeight % printableAreaHeight);

 

else

 

rectangleHeight = printableAreaHeight;

}

 

else

 

{

rectangleHeight = printableAreaHeight;

}

rt =

new ImageTools.Rectangle(xCoordinate, yCoordinate,

 

ActualImageWidth, rectangleHeight);

 

//slices the image to multiple images(multiple pages) and adds to an images list

 

images.Add(ExtendedImage.Crop(ei, rt));

}

 

var bitmapImage = new BitmapImage();

 

bitmapImage.SetSource(images[_currentPage].ToStream());

 

var imageBrush = new ImageBrush();

 

imageBrush.ImageSource = bitmapImage;

 

var rectangle = new System.Windows.Shapes.Rectangle

 

{

Width = bitmapImage.PixelWidth,

Height = bitmapImage.PixelHeight,

Fill = imageBrush

};

box.Child = rectangle;

box.StretchDirection = StretchDirection.Both;

box.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

 

 

e.PageVisual = box;

//sets the pagevisual to print

 

++_currentPage;

 

if (_currentPage < NoOfPages) //Checks if there are more pages to print

 

e.HasMorePages =

true;

 

};

pd.EndPrint += (s, e) =>

{

p.Width = originalWidth;

p.Height = originalHeight;

};

pd.Print(

"Assessment Report");

 

}

Tags
General Discussions
Asked by
Nambi
Top achievements
Rank 1
Share this question
or