Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Letter spacing issue while converting FlowDocument to Xps using Justify Alignment

$
0
0

I got a strange problem in an application converting FlowDocument to Xps. I condensed the app to a little scenario. Xaml:

<Grid><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition /></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="auto" /><RowDefinition /></Grid.RowDefinitions><Button Click="Button_Click">Create Xps</Button><RichTextBox Name="rtb" Grid.Row="1"><FlowDocument><Paragraph TextAlignment="Justify" FontFamily="Calibri" FontSize="14.6666666666667">Robin Friday (1952–1990) was an English football forward who played for Reading and Cardiff City during the mid-1970s. Born and raised in Acton in west London, Friday joined Reading in 1974, quickly becoming a key player and helping Reading win promotion to the Third Division during the 1975–76 season. Friday won Reading's player of the year award in both of his full seasons there as their leading goal scorer.</Paragraph></FlowDocument></RichTextBox><DocumentViewer Grid.Row="1" Grid.Column="1" Name="dv" /></Grid>

Code:

        void Button_Click(object sender, RoutedEventArgs e)
        {
            MemoryStream stream = new MemoryStream(1024);
            Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite);
            string name = "memorystream://" + DateTime.Now.Ticks + ".xps";
            PackageStore.AddPackage(new Uri(name), package);
            XpsDocument doc = new XpsDocument(package, CompressionOption.Fast, name);
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);

            Size pageSize = new Size(800, 300);
            Thickness margin = new Thickness(20);
            rtb.Document.PageHeight = pageSize.Height;
            rtb.Document.PageWidth = pageSize.Width;
            rtb.Document.ColumnGap = 0;
            rtb.Document.PagePadding = new Thickness(0);
            rtb.Document.ColumnWidth = rtb.Document.PageWidth - margin.Left - margin.Right;

            DocumentPaginator paginator = ((IDocumentPaginatorSource)rtb.Document).DocumentPaginator;

            writer.Write(paginator);
            dv.Document = doc.GetFixedDocumentSequence();
        }

The Xps looks somewhat strange. You get some additional spaces dividing words. For example the word "during" in "Cardiff City during the" gets some space between the "du" and the "ring". (sorry a pic would have been best here, a pity I'm not allowed to post one... Could anyone verify my acc?). When you select those words and c&p them e.g. to word the mysterious spaces will be a normal whitspace. Any idea how to avoid this problem?

Also on StackOverflow: http://stackoverflow.com/questions/31125156/letter-spacing-issue-while-converting-flowdocument-to-xps-using-justify-alignmen


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>