Dear community
I try create pdf file with content from rtf-string
But positions of parts of line are not correct
Here is my example
Code:
......
PdfSharp.Pdf.PdfDocument xDoc = new PdfSharp.Pdf.PdfDocument();
xDoc.Pages.Add(new PdfSharp.Pdf.PdfPage() { Width = 500, Height = 750 });
xDoc.Info.Author = “Autor";
xDoc.Info.CreationDate = DateTime.Now;
xDoc.Info.Creator = "Creator";
xDoc.Info.Keywords = "KW1, KW2, KW3";
xDoc.Info.Subject = "Subject";
xDoc.Info.Title = "Title";
PdfSharp.Pdf.PdfPage xPage = xDoc.Pages[0];
PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(xPage);
PdfSharp.Drawing.XPen pen = new PdfSharp.Drawing.XPen(PdfSharp.Drawing.XColor.FromKnownColor(KnownColor.Red), 0.5);
PdfSharp.Drawing.Layout.XTextFormatter tf = new PdfSharp.Drawing.Layout.XTextFormatter(gfx);
tf.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Left;
////myRichTextBox contain text Test1_Test2_Test3
myRichTextBox.Select(0, 6);
string str0 = myRichTextBox.SelectedText;
Font f0 = myRichTextBox.SelectionFont;
Point p0 = myRichTextBox.GetPositionFromCharIndex(0);
SizeF size0 = gfx.Graphics.MeasureString(str0, f0);
PdfSharp.Drawing.XRect xR0 = new PdfSharp.Drawing.XRect();
xR0.Width = size0.Width;
xR0.Height = size0.Height;
xR0.X = p0.X;
xR0.Y = p0.Y;
d2.RichTextBox.Select(6, 6);
string str1 = d2.RichTextBox.SelectedText;
Font f1 = myRichTextBox.SelectionFont;
Point p1 = myRichTextBox.GetPositionFromCharIndex(6);
SizeF size1 = gfx.Graphics.MeasureString(str1, f1);
PdfSharp.Drawing.XRect xR1 = new PdfSharp.Drawing.XRect();
xR1.Width = size1.Width;
xR1.Height = size1.Height;
xR1.X = p1.X;
xR1.Y = p1.Y;
myRichTextBox.Select(12, 5);
string str2 = myRichTextBox.SelectedText;
Font f2 = myRichTextBox.SelectionFont;
Point p2 = myRichTextBox.GetPositionFromCharIndex(12);
SizeF size2 = gfx.Graphics.MeasureString(str2, f2);
PdfSharp.Drawing.XRect xR2 = new PdfSharp.Drawing.XRect();
xR2.Width = size2.Width;
xR2.Height = size2.Height;
xR2.X = p2.X;
xR2.Y = p2.Y;
PdfSharp.Drawing.XFont xf0 = new PdfSharp.Drawing.XFont(f0.FontFamily.Name, f0.Size, (PdfSharp.Drawing.XFontStyle)f0.Style);
PdfSharp.Drawing.XFont xf1 = new PdfSharp.Drawing.XFont(f1.FontFamily.Name, f1.Size, (PdfSharp.Drawing.XFontStyle)f1.Style);
PdfSharp.Drawing.XFont xf2 = new PdfSharp.Drawing.XFont(f2.FontFamily.Name, f2.Size, (PdfSharp.Drawing.XFontStyle)f2.Style);
PdfSharp.Drawing.XBrush xBrush = new System.Drawing.SolidBrush(Color.Red);
PdfSharp.Drawing.XBrush xBrushRect0 = new System.Drawing.SolidBrush(Color.LightBlue);
PdfSharp.Drawing.XBrush xBrushRect1 = new System.Drawing.SolidBrush(Color.LightSlateGray);
PdfSharp.Drawing.XBrush xBrushRect2 = new System.Drawing.SolidBrush(Color.LightSkyBlue);
gfx.DrawRectangle(xBrushRect0, xR0);
gfx.DrawRectangle(xBrushRect1, xR1);
gfx.DrawRectangle(xBrushRect2, xR2);
tf.DrawString(str0, xf0, xBrush, xR0);
tf.DrawString(str1, xf1, xBrush, xR1);
tf.DrawString(str2, xf2, xBrush, xR2);
xDoc.PageLayout = PdfSharp.Pdf.PdfPageLayout.SinglePage;
xDoc.Save(fileFN);
xDoc.Close();
......
If I draw same parts with same positions on WinForm all is correct. But in pdf I see that distances between parts are more as needed. Is one bug or is my mistake?
Thanks in advance