PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 16, 2024 7:50 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
 Post subject: LineBreaks
PostPosted: Thu Oct 27, 2016 9:43 pm 
Offline

Joined: Thu Oct 27, 2016 9:15 pm
Posts: 3
In using XTextFormatter or XGraphics, I can't get "\n" to cause a linebreak with DrawString. The "\n" just displays as part of the text. Are there other ways to try?

Also, if I have a Xrect box, is just one Drawstring allowed or is there a way to have more than one DrawString position text in the same Xrect box.

thanks
mark


Top
 Profile  
Reply with quote  
 Post subject: Re: LineBreaks
PostPosted: Sat Oct 29, 2016 1:18 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 913
Location: CCAA
Hi!
meh wrote:
The "\n" just displays as part of the text. Are there other ways to try?
You don't show any code. "\n" will not work when you prefix the string with "@".
XGraphics no longer supports "\n" as of PDFsharp 1.50. It should work with XTextFormatter.

meh wrote:
Also, if I have a Xrect box, is just one Drawstring allowed or is there a way to have more than one DrawString position text in the same Xrect box.
You can draw multiple texts at the same or at overlapping positions.

See also:
viewtopic.php?f=2&t=832

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: LineBreaks
PostPosted: Sat Oct 29, 2016 4:19 pm 
Offline

Joined: Thu Oct 27, 2016 9:15 pm
Posts: 3
Thanks Thomas... after serving my time in the corner.

PdfSharp-WPF-1.50-NuGet

Code:
Dim PdfDocument = New PdfDocument()
Dim PdfPage = PdfDocument.AddPage()
Dim gfx = XGraphics.FromPdfPage(PdfPage)
Dim font = New XFont("Times New Roman", 10, XFontStyle.Bold)
Dim Brush = XBrushes.Purple
Dim tf = New XTextFormatter(gfx)
Dim rect = New XRect(40, 50, 250, 160)
' Dim pdfrect = New PdfRectangle(rect)
PdfDocument.PageLayout = PdfPageLayout.SinglePage
tf.Alignment = XParagraphAlignment.Right
gfx.DrawRectangle(XBrushes.LightGray, rect)
' PdfPage.AddWebLink(pdfrect, "www.greencrazy.com\images\tbe1234.jpg")
tf.DrawString("test of \n linebreak.", font, Brush, rect, XStringFormats.TopLeft)
PdfDocument.Save("test_linebreak.pdf")
Process.Start("test_linebreak.pdf")

This just displays \n as part of sentence. Have tried several variations.

Additional question... can a hyperlink be added in the drawstring text with PDFsharp?

Thanks
Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: LineBreaks
PostPosted: Sat Oct 29, 2016 9:19 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 913
Location: CCAA
meh wrote:
This just displays \n as part of sentence. Have tried several variations.
Have you tried C#, too?
"\n" is the notation for the C# compiler.

With VB you have try something like this:
"This is the contents of the annotation." & vbCr & "This is the 2nd line."
Or this (this is "\n" in VB notation):
"This is the contents of the annotation." & vbLf & "This is the 2nd line."
Or this:
"This is the contents of the annotation." & vbCrLf & "This is the 2nd line."

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: LineBreaks
PostPosted: Mon Oct 31, 2016 12:49 pm 
Offline

Joined: Thu Oct 27, 2016 9:15 pm
Posts: 3
I thought I had tried the VbCr.. and didn't now that \n was c only... sheesh.. learning.

Anyway VbCr works... thanks for your patience.


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 78 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group