PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

DrawString trims the text
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3027
Page 1 of 1

Author:  nav3000 [ Mon Jan 12, 2015 10:04 am ]
Post subject:  DrawString trims the text

Dear community
I try create one pdf file with text, which contain also space symbols.

I use the method XGrapics.DrawString. But by using of any fonts – the text in the pdf file is trimmed.
For example the text is "Aaaaa EG ggggggggggggggggggggg", but in pdf file I can see only „Aaaaa EG“

The text is trimmed if I use follows fonts

BaskervilleOldFace
BookmanOldStyle
Century
CenturyGothic
CenturySchoolbook
Elephant
JuiceITC
LucidaBright
LucidaCalligraphy
LucidaFax
LucidaHandwriting
MaiandraGD
MicrosoftJhengHei
MicrosoftUighur
MoolBoran
ShonarBangla
SnapITC
Swis721BdCnOulBT
Swis721BdOulBT
Swis721BlkBT
Swis721BlkCnBT
Swis721BlkExBT
Swis721BlkOulBT
Swis721BT
Swis721CnBT
Swis721ExBT
Swis721LtBT
Swis721LtCnBT
Swis721LtExBT
Symbol
WideLatin

How solve I this problem?
Thanks in advance

Author:  Thomas Hoevel [ Mon Jan 12, 2015 12:59 pm ]
Post subject:  Re: DrawString trims the text

Hi!
nav3000 wrote:
How solve I this problem?
I don't understand the problem. Some more information and some more code might help me to understand the problem.
What are "space symbols"?

Author:  nav3000 [ Mon Jan 12, 2015 2:59 pm ]
Post subject:  Re: DrawString trims the text

Also „space symbol“ is symbol which entered with space key of keyboard.
Between words in texts are space symbols.
I have gived one string as example. „Aaaaa EG ggggggggggggggggggggg“
I make pdf file ONLY with this string.
Code:
double s = 12;
PdfSharp.Drawing.XFont f = new PdfSharp.Drawing.XFont("Swis721 Blk BT", s, PdfSharp.Drawing.XFontStyle.Regular, options0);
               
PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(200, 100), size);
xTextFormatter0.DrawString("Aaaaa EG ggggggggggggggggggggg", f, brush, rect);


With font family name "Swis721 Blk BT" (or with fonts from my list) I have pdf file with text
„Aaaaa EG“. Where is rest of text???

Author:  Thomas Hoevel [ Mon Jan 12, 2015 4:14 pm ]
Post subject:  Re: DrawString trims the text

I tried "Lucida Fax" and it worked as expected.
Code:
XTextFormatter xTextFormatter0 = new XTextFormatter(gfx);
XPdfFontOptions options0 = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Always);
XSize size = new XSize(400, 400);
XBrush brush = XBrushes.Black;

double s = 12;
PdfSharp.Drawing.XFont f = new PdfSharp.Drawing.XFont("Lucida Fax", s, PdfSharp.Drawing.XFontStyle.Regular, options0);

PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(200, 100), size);
xTextFormatter0.DrawString("Aaaaa EG ggggggggggggggggggggg", f, brush, rect);
The four leading lines initialize objects that were missing in your code snippet.

Please provide an SSCCE if you think there is a bug in PDFsharp.

Author:  nav3000 [ Tue Jan 13, 2015 8:20 am ]
Post subject:  Re: DrawString trims the text

Now I understand where is problem. Namely I take size for rectangle by MeasureString

Code:
double s = 12;
PdfSharp.Drawing.XFont f = new PdfSharp.Drawing.XFont("Swis721 Blk BT", s, PdfSharp.Drawing.XFontStyle.Regular, options0);
PdfSharp.Drawing.XSize size = gfx.MeasureString("Aaaaa EG ggggggggggggggggggggg", f);


PdfSharp.Drawing.XRect rect = new PdfSharp.Drawing.XRect(new PdfSharp.Drawing.XPoint(200, 100), size);
xTextFormatter0.DrawString("Aaaaa EG ggggggggggggggggggggg", f, brush, rect);


Thank you for help

Author:  Thomas Hoevel [ Thu Jan 15, 2015 9:06 am ]
Post subject:  Re: DrawString trims the text

A note (for nav3000 and other readers here):
The XGraphics class (gfx object) has several DrawString methods that can be used if you do not need automatic line breaks.

The XTextFormatter class is a wrapper that supports line breaks, but internally it invokes gfx.DrawString().

You can skip the call to gfx.MeasureString() and call gfx.DrawString() directly, passing only a point (without size).
You should get the same result: text in one line - and if the text is too long it will continue across the page border.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/