Silverlight で複数のページを印刷する方法。実際には、Silverlight にシナリオがあり、1 ページのすべてのコンテンツを印刷でき、余分なコンテンツがすべて削除されたボタン クリック イベントがありますが、次のページが印刷されません。
これは私のボタンクリックイベントです
private void btnSubmitPrint_Click(object sender, RoutedEventArgs e)
{
_currentIndex = 0;
PrintDocument docprin = new PrintDocument();
docprin.PrintPage += new EventHandler<PrintPageEventArgs>(docprin_PrintPage);
string DocumentName = "Balaji";
docprin.Print(DocumentName);
}
//I Combine all the List into to a single string by using Linq
void docprin_PrintPage(object sender, PrintPageEventArgs e)
{
string delimeter = "\n";
var checkval = ListOfPageComments.Select(i => i.Comment.Insert(100, Environment.NewLine));//This lINQ OPERATION
var ListofPagecommentsAscending = from n in ListOfPageComments orderby n.Date descending select n;
var CommentsLineBreaks = ListofPagecommentsAscending.Select(conmmentss =>
{
var retur = conmmentss;
if (conmmentss.Comment.Length > 100)
{
IEnumerable<string> spllitingvaluetoNewLine = (Enumerable.Range(0, conmmentss.Comment.Length / 100).Select(j => conmmentss.Comment.Substring(j * 100, 100)));
string RejoiningLinestoSingle = String.Join(" \n ", spllitingvaluetoNewLine);
conmmentss.Comment = RejoiningLinestoSingle;
return conmmentss;
}
return conmmentss;
});
var delimitedcomments = CommentsLineBreaks.Select(i => i.Date + "\n" + i.Comment).Aggregate((i, j) => i + delimeter + j);
string Printcomments = String.Join(delimeter, delimitedcomments);
List<string> get = (Enumerable.Range(0, Printcomments.Length / 800).Select(j => Printcomments.Substring(j * 800, 800))).ToList();
//AFTER GETTING THE VALUE OF STRING I SPLIT THEM INTO A LIST
while (_currentIndex < get.Count())//lOOPING CONDITION TO PRINT MULTIPLE PAGES
{
var pageRoot = new Canvas();
e.PageVisual = pageRoot;
_currentTop = PAGEMARGIN;
_availableSpace = e.PrintableArea.Height - PAGEMARGIN * 2;
// var txt = new TextBlock { Text = Printcomments };
var txt = new TextBlock { Text = get[_currentIndex].ToString() };
if (ROWHEIGHT > _availableSpace)
{
e.HasMorePages = true;
break;
}
txt.SetValue(Canvas.TopProperty, _currentTop);
txt.SetValue(Canvas.LeftProperty, PAGEMARGIN);
_currentTop += ROWHEIGHT;
_availableSpace -= ROWHEIGHT;
pageRoot.Children.Add(txt);
_currentIndex++;
}
}