Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打印WPF段落时,在显示没有边框的段落时会呈现边框_Wpf_Printing - Fatal编程技术网

打印WPF段落时,在显示没有边框的段落时会呈现边框

打印WPF段落时,在显示没有边框的段落时会呈现边框,wpf,printing,Wpf,Printing,我在打印带有段落的流程文档时遇到问题。当我在窗口中显示FlowDocument时,段落在没有边框的情况下正确呈现 但是,当我打印它们时(我在这个阶段只能测试打印到PDF,所以我无法确认打印到纸张时这是否仍然是一个问题),生成的PDF文档在每个段落周围都有一个边框 打印时如何从文档中删除这些边框 这是我用来打印流程文档的代码: LocalPrintServer localPrintServer = new LocalPrintServer(); PrintQueue printQueue =

我在打印带有段落的流程文档时遇到问题。当我在窗口中显示FlowDocument时,段落在没有边框的情况下正确呈现

但是,当我打印它们时(我在这个阶段只能测试打印到PDF,所以我无法确认打印到纸张时这是否仍然是一个问题),生成的PDF文档在每个段落周围都有一个边框

打印时如何从文档中删除这些边框

这是我用来打印流程文档的代码:

LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue printQueue = localPrintServer.DefaultPrintQueue;

// Create a XpsDocumentWriter object, open a Windows common print dialog.
// This methods returns a ref parameter that represents information about the dimensions of the printer media.
XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(printQueue);
PageImageableArea ia = printQueue.GetPrintCapabilities().PageImageableArea;
PrintTicket pt = printQueue.UserPrintTicket;

if (docWriter != null && ia != null)
{
    DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDoc).DocumentPaginator;
    // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
    paginator.PageSize = new Size((double)ia.ExtentWidth, (double)ia.ExtentHeight);
    Thickness pagePadding = flowDoc.PagePadding;
    flowDoc.PagePadding = new Thickness(
    Math.Max(ia.OriginWidth, pagePadding.Left),
    Math.Max(ia.OriginHeight, pagePadding.Top),
    Math.Max((double)pt.PageMediaSize.Width - (double)(ia.OriginWidth + ia.ExtentWidth), pagePadding.Right),
    Math.Max((double)pt.PageMediaSize.Height - (double)(ia.OriginHeight + ia.ExtentHeight), pagePadding.Bottom));
    flowDoc.ColumnWidth = double.PositiveInfinity;
    // Send DocumentPaginator to the printer.
    docWriter.Write(paginator);
}

我发现这个问题的原因是名为的元素。 修复方法是将名称更改为null

var elementWithName = (ElementType)clone.FindName("elementName");
elementWithName.Name = null;
其中ElementType可以是:(从中拍摄的图像)


克隆是一个流程文档