Я пытаюсь напечатать FlowDocument
с PrintDialog
в файл XPS. Полученное печатное содержимое растягивается только на половину страницы XPS, а не на всю ширину страницы. Вот пример того, как итоговый документ XPS выглядит в средстве просмотра Windows XPS:
(примечание: это выглядит точно так же, если я печатаю его на принтере на обычной бумаге для печати 8x11)
Это код, который я использую для печати этого документа:
void Print()
{
PrintDialog printDialog = new PrintDialog();
bool? result = printDialog.ShowDialog();
if (!result.HasValue)
return;
if (!result.Value)
return;
double pageWidth = printDialog.PrintableAreaWidth;
double pageHeight = printDialog.PrintableAreaHeight;
FlowDocument flowDocument = CreateFlowDocument(pageWidth, pageHeight);
printDialog.PrintDocument(
((IDocumentPaginatorSource)flowDocument).DocumentPaginator,
"Test print job");
}
FlowDocument CreateFlowDocument(double pageWidth, double pageHeight)
{
FlowDocument flowDocument = new FlowDocument();
flowDocument.PageWidth = pageWidth;
flowDocument.PageHeight = pageHeight;
flowDocument.PagePadding = new Thickness(30.0, 50.0, 20.0, 30.0);
flowDocument.IsOptimalParagraphEnabled = true;
flowDocument.IsHyphenationEnabled = true;
flowDocument.IsColumnWidthFlexible = true;
Paragraph header = new Paragraph();
header.FontSize = 18;
header.Foreground = new SolidColorBrush(Colors.Black);
header.FontWeight = FontWeights.Bold;
header.Inlines.Add(new Run("Title of my document (will be cut off in XPS)";));
flowDocument.Blocks.Add(header);
Paragraph test = new Paragraph();
test.FontSize = 12;
test.Foreground = new SolidColorBrush(Colors.Black);
test.FontWeight = FontWeights.Bold;
test.Inlines.Add(new Run("This text should stretch across the entire width of the page. Let's see if it really does, though."));
flowDocument.Blocks.Add(test);
return flowDocument;
}
pageWidth
равно 816.0 , а pageHeight
равно 1056.0 , что должно быть на больше , чем достаточно большое, чтобы вместить мой текст. Что может быть не так?
Редактировать: Вот еще несколько вещей, которые я пробовал:
- Попытался добавить
StackPanel
с большой шириной к моему Paragraph
в FlowDocument
. Текст просто обрезается на половине страницы.
- Попытка присвоения
FlowDocument.PageWidth
большой ширине. Опять же, текст просто обрезается примерно посередине страницы.