PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 4:25 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Jan 12, 2015 10:04 am 
Offline

Joined: Fri Sep 06, 2013 7:01 am
Posts: 27
Location: Cologne, Germany
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 12, 2015 12:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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"?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 12, 2015 2:59 pm 
Offline

Joined: Fri Sep 06, 2013 7:01 am
Posts: 27
Location: Cologne, Germany
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???


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 12, 2015 4:14 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 13, 2015 8:20 am 
Offline

Joined: Fri Sep 06, 2013 7:01 am
Posts: 27
Location: Cologne, Germany
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 15, 2015 9:06 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group