我从数据源动态填充流程文档的内容。样板文件(即标题,标题等)是在XAML中定义的,其内容将被插入到代码中的占位符元素中。
当通过“ microsoft Print to PDF”打印机打印文档时,在XAML中设置了“ x:Name”属性的所有元素都被黑色边框包围,尽管我既未设置任何border参数,也未设置该border显式设置为“ x:Null”,厚度设置为“ 0”将其删除。其他PDF打印机(例如PDF24甚至是microsoft的XPS Document Writer)在元素周围没有任何边框。
如何消除此边框,因为它确实破坏了打印布局?
下面的代码为一个简单的示例。
- MyFlowDocument.xaml(在代码隐藏中没有逻辑):
<FlowDocument x:Class="FlowDocumentGenerator.MyFlowDocument"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Paragraph x:Name="_paragraph" BorderBrush="{x:Null}" BorderThickness="0">I have a name and want no frame.</Paragraph>
<Paragraph>I do not have an name and no frame.</Paragraph>
</FlowDocument>
- MainWindow.xaml.cs(XAML中没有标记):
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace FlowDocumentGenerator
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender,RoutedEventArgs e)
{
var dialog = new PrintDialog();
if (dialog.ShowDialog() ?? false)
{
var paginator = ((IDocumentPaginatorSource)new MyFlowDocument()).DocumentPaginator;
dialog.PrintDocument(paginator,string.Empty);
}
Close();
}
}
}