PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 23, 2024 9:04 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu May 01, 2014 1:27 am 
Offline

Joined: Thu May 01, 2014 1:12 am
Posts: 1
Hello,

I'm using PDFSharp 1.31.1789.0 to write text to small rectangle. I'd like for the text to not word wrap if it reaches the right edge of the rectangle as it does now. Instead, I'd like to the text to be clipped / truncated. What do I need to do to get this behavior?

e.g. The following code:
Code:
Dim gfx As XGraphics = XGraphics.FromPdfPage(p)
Dim font As New XFont("Times New Roman", 10, XFontStyle.Bold)
Dim tf As New XTextFormatter(gfx)

Dim rect As New XRect(0, 0, 160, 60)
gfx.DrawRectangle(XBrushes.SeaShell, rect)

Dim s As String = String.Format("Line A{0}Line B{0}Line C: I do not want this line to wrap to the next line if there isn't space.  I want it to remain on a single line and clipped on the right.{0}Line D", vbNewLine)
tf.DrawString(s, font, XBrushes.Black, rect, XStringFormats.TopLeft)

produces something like this:
Quote:
Line A
Line B
Line C: I do not want this line to
wrap to the next line if there isn't
space. I want it to remain on a single


Instead, I'd like for it to produce this:
Quote:
Line A
Line B
Line C: I do not want this line to
Line D

What do I need to do to get this output? Thanks in advanced!


Top
 Profile  
Reply with quote  
PostPosted: Sat May 03, 2014 6:04 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
Hi!

gfx.DrawString keeps the text on one line, but does not clip it.
tf.DrawString wraps the text to the next line, but does not clip it.

Use the XTextFormatter class to get started, but modify it as you need it. Find out how much text fits in one line, draw only that text, ignore the rest.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 181 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