我有一个打印FlowDocument的功能如下:
public static void printDocument(FlowDocument printDocument)
{
TextRange sourceDocument = new TextRange(printDocument.ContentStart, printDocument.ContentEnd);
MemoryStream stream = new MemoryStream();
sourceDocument.Save(stream, DataFormats.Xaml);
FlowDocument flowDocumentCopy = new FlowDocument();
TextRange copyDocumentRange = new TextRange(flowDocumentCopy.ContentStart, flowDocumentCopy.ContentEnd);
copyDocumentRange.Load(stream, DataFormats.Xaml);
PrintDocumentImageableArea ia = null;
XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(ref ia);
if (docWriter != null && ia != null)
{
DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocumentCopy).DocumentPaginator;
paginator.PageSize = new System.Windows.Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
Thickness pagePadding = flowDocumentCopy.PagePadding;
flowDocumentCopy.PagePadding = new Thickness(
Math.Max(ia.OriginWidth, pagePadding.Left),
Math.Max(ia.OriginHeight, pagePadding.Top),
Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), pagePadding.Right),
Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), pagePadding.Bottom));
flowDocumentCopy.ColumnWidth = double.PositiveInfinity;
docter.Write(paginator);
}
}
当我打印文档时,段落间距的间隙太大了......它有点浪费纸张..有没有办法让我删除段落间距,或者缩小空间?
<RichTextBox AcceptsTab="True" AllowDrop="True" BorderThickness="1" FontFamily="Lucida Console" FontSize="10" IsReadOnly="True" Margin="0" Name="TxtSource" Padding="0" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="#FF8C8E94" >
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Block.Margin" Value="0" />
</Style>
</RichTextBox.Resources>