Label control - Border lines issue on PDF export

Balamurugan Rajaraman 5 Reputation points

I attempted to export a Label control with a white background and noticed some border lines in the output file. Is there a workaround for this problem?

UI As seen below:


Exported output


Xaml Code


Code Used for Printing

private void Button_Click(object sender, RoutedEventArgs e)
        var filename = SaveCurrentDocument();
        PrintDialog printDialog = new PrintDialog();
        if ((bool)printDialog.ShowDialog())
            PrintXPSDocument(printDialog, filename);

    public string SaveCurrentDocument()
        var filename = @"D:\exportWPF.xps";
        using (Stream stream = File.Create(filename))

        return filename;

    private void InvokeXps(Stream stream)
        FixedDocument fixedDoc = new FixedDocument();
        PageContent pageContent = new PageContent();
        FixedPage fixedPage = CreateFixedPage(new Rect(0, 0, 500, 500));


        Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite);
        XpsDocument doc = new XpsDocument(package);
        XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);

    internal FixedPage CreateFixedPage(Rect area)
        VisualBrush visualBrush = new VisualBrush(sampleCanvas);
        System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
        RenderOptions.SetBitmapScalingMode(visualBrush, BitmapScalingMode.HighQuality);
        visualBrush.Stretch = Stretch.None;
        visualBrush.ViewboxUnits = BrushMappingMode.Absolute;
        visualBrush.Viewbox = area;
        rect.Fill = visualBrush;
        rect.Stretch = Stretch.Fill;
        rect.Width = area.Width;
        rect.Height = area.Height;
        rect.Arrange(new Rect(area.Size));

        FixedPage fp = new FixedPage();
        fp.Width = area.Width;
        fp.Height = area.Height;
        fp.Arrange(new Rect(area.Size));
        return fp;

    internal void PrintXPSDocument(PrintDialog printDialog, string filePath)
        var document = new XpsDocument(filePath, FileAccess.Read);
        var sequence = document.GetFixedDocumentSequence();
        FixedDocument fixedDocument = sequence.References[0].GetDocument(false);
        fixedDocument.DocumentPaginator.PageSize = new System.Windows.Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
        printDialog.PrintDocument(fixedDocument.DocumentPaginator, "Printing");

I attempted to export my canvas control to.xps format and then print it using the Print Dialog via the shared code.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,185 questions
No comments
1 vote