Сетка, которую я печатаю, содержит не только сетку данных (которая объединяется так, что в таблице появляются только выбранные строки). соответствующую страницу), но также верхние и нижние колонтитулы, содержащие поля со списком, текстовые поля или текстовые блоки, большинство из которых свернуты, а некоторые активированы (например, текстовое поле с номером страницы) для печати.
Мой код (после вызова PrintDialog):
Код: Выделить всё
//Create FixedDocument
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight);
//Add pages
ObservableCollection pages = new ObservableCollection();
for (pageNumber = 1; pageNumber = actualRowCount && totalsLine))
{
Grid thisGrid = new Grid();
thisGrid = grdPastTransactions;
UIElement uiElement = thisGrid;
var parent = VisualTreeHelper.GetParent(thisGrid) as Grid;
if (parent != null)
{
parent.Children.Remove(uiElement);
}
pages[pageNumber - 1].Width = document.DocumentPaginator.PageSize.Width;
pages[pageNumber - 1].Height = document.DocumentPaginator.PageSize.Height;
pages[pageNumber - 1].Children.Add(thisGrid);
//Add page to document
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(pages[pageNumber - 1]);
document.Pages.Add(page1Content);
}
pageRowCount += pageNumber == 1 ? Math.Min(actualRowCount, firstPageLines) : 28;
}
//Print document
PrintMethods.PrintHelper.PrintNoPreview(printDlg, document);
Код: Выделить всё
public static void PrintNoPreview(PrintDialog printDialog, FixedDocument fixedDoc)
{
try
{
printDialog.PrintDocument(fixedDoc.DocumentPaginator, "PMM Report");
}
catch (System.Runtime.CompilerServices.RuntimeWrappedException)
{
MessageBox.Show("You are trying to over-write an existing PDF document of the same name which is open." +
"\n\nPlease close the old document and try again, or save the new document with a new name.", "Save to PDF failed", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Почему я не могу добавлять страницы в Фиксированный документ без генерации этой ошибки? Нужно ли мне создавать совершенно новую сетку (со всеми новыми элементами) для печати?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -the-logic