I've got an issue when trying to print a FlowDocument with paragraphs. When I display the FlowDocument in a window, the paragraphs are rendered correctly without a border.
However, when I print them (I can only test printing to PDF at this stage, so I can't confirm if this is still an issue when printed to paper), the resulting PDF document has a border around each paragraph.
How can I remove these borders from the document when printing?
This is the code I'm using to print the FlowDocument:
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);
}