PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
Clip text if end of rectangle is reached https://forum.pdfsharp.net/viewtopic.php?f=2&t=2806 |
Page 1 of 1 |
Author: | flashchase [ Thu May 01, 2014 1:27 am ] |
Post subject: | Clip text if end of rectangle is reached |
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! |
Author: | () => true [ Sat May 03, 2014 6:04 pm ] |
Post subject: | Re: Clip text if end of rectangle is reached |
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. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |