Reputation: 1189
I am implementing silverlight printing using PrintDocument
. My UI is generated runtime using XamlReader
which parse xaml
which I have stored in db.
Here is code:
string str = sb.ToString();
newUI = XamlReader.Load(sb.ToString()) as FrameworkElement;
newUI.DataContext = ReportData;
grdPreviewArea.Children.Add(newUI);
grdPreviewArea.Height = pageHeight;
grdPreviewArea.Width = pageWidth;
Grid.SetColumn(newUI, 1);
Grid.SetRow(newUI, 1);
Now to print I am setting newUI
as e.PageVisual
in my print event handle.
This works fine if rendered UI is fits single page , but I am not able to print second page if it does not fits single page.
Upvotes: 0
Views: 81
Reputation: 2872
First you need to work out how many pages are needed
Dim pagesNeeded As Integer = Math.Ceiling(gridHeight / pageHeight) //gets number of pages needed
Then once the first page has been sent to the printer, you need to move that data out of view and bring the new data into view ready to print. I do this by converting the whole dataset into an image/UI element, i can then adjust Y value accordingly to bring the next set of required data on screen.
transformGroup.Children.Add(New TranslateTransform() With {.Y = -(pageIndex * pageHeight)})
Then once the number of needed pages is reached, tell the printer to stop
If pagesLeft <= 0 Then
e.HasMorePages = False
Exit Sub
Else
e.HasMorePages = True
End If
Or if this is too much work, you can simply just scale all the notes to fit onto screen. Again probably by converting to UI element.
Check out this link for converting to a UI element.
http://www.codeproject.com/Tips/248553/Silverlight-converting-to-image-and-printing-an-UI
Hope this helps
Upvotes: 1