PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Mar 05, 2013 11:52 am 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 05, 2013 1:38 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!

Use the XTextFormatter class.

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 11, 2013 3:30 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
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)


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 11, 2013 3:48 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 11, 2013 4:27 pm 
Offline

Joined: Mon Nov 19, 2012 11:54 am
Posts: 16
I am a tool, my fault is cause I just pressed the number 2 so there were no gaps.


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

All times are UTC


Who is online

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