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

Adding a carrige return within the text
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2353
Page 1 of 1

Author:  silentbob [ Tue Mar 05, 2013 11:52 am ]
Post subject:  Adding a carrige return within the text

Hello All,

Im having a bit of trouble. I am using VB to create a pdf using data from a webspage. I have just added in a text box (multiline) so the user can type some comments and these are then copied to the pdf when a button is clicked. The problem I am having is how to create a carrige return (or new line) in the middle of the text as if I just copy whats there if its too long it just places it off the page.

This is what I have so far and it adds the textbox's text to the pdf but it goes off the page if the text is too long.

Code:
gfx.DrawString("Comments:" & " " & RWETcomments.Text, font, XBrushes.Black, New XRect(20, 555, 0, 0), XStringFormats.TopLeft)


Quite difficult to describe, hope it makes sense. Difficult to google as well.

Author:  Thomas Hoevel [ Tue Mar 05, 2013 1:38 pm ]
Post subject:  Re: Adding a carrige return within the text

Hi!

Use the XTextFormatter class.

It will reflect linebreaks coming from the text, but will also break long lines automatically.

Author:  silentbob [ Mon Mar 11, 2013 3:30 pm ]
Post subject:  Re: Adding a carrige return within the text

I have been playing about with the xtextformatter class but to no avail. I have the code below so far but it just puts one long line.

Code:
        Dim text As String = RWETcomments.Text
        Dim xtextformatter As New XTextFormatter(gfx)
        Dim rect As New XRect(40, 100, 250, 220)

        gfx.DrawRectangle(XBrushes.SeaShell, rect)
        xtextformatter.Alignment = XParagraphAlignment.Left
        xtextformatter.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft)

Author:  Thomas Hoevel [ Mon Mar 11, 2013 3:48 pm ]
Post subject:  Re: Adding a carrige return within the text

silentbob wrote:
I have the code below so far but it just puts one long line.
Does it work with the text from the sample instead? You have to replace '\n' by e.g. VBCrLf.
Or with similar text specified in your code?

You don't show the text you use for testing, you don't show the resulting PDF. Difficult to help with just a small code snippet.
XTextFormatter should break lines at any whitespace. Is there whitespace in your test text?

Author:  silentbob [ Mon Mar 11, 2013 4:27 pm ]
Post subject:  Re: Adding a carrige return within the text

I am a tool, my fault is cause I just pressed the number 2 so there were no gaps.

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