PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Mon Sep 29, 2025 12:22 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: PdfSharp line breaks
PostPosted: Wed Apr 23, 2008 11:57 am 
Offline

Joined: Wed Apr 23, 2008 11:48 am
Posts: 1
Dear all,

I'm creating a pdf document with a long text in it. Problem is the text runs out of the page. How can i make the text stay within page boundaries?

Also i would like to know how to force a linebreak within the text (vbCrlF doesn't work)

Nice software by the way really time saving.


kind regards,
Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Tue Jun 23, 2009 10:24 pm 
Offline

Joined: Tue Jun 23, 2009 10:22 pm
Posts: 1
Sorry to bump this thread up, but i have the same problem.


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Wed Jun 24, 2009 12:11 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
If you use MigraDoc, MigraDoc will take care of page breaks.

If you use PDFsharp to create PDF documents, then it's your task to detect page breaks and create new pages as necessary.

See also here:
viewtopic.php?f=1&t=1&p=1&hilit=page+breaks+line#p1

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Wed Jan 06, 2010 2:27 pm 
Offline

Joined: Mon Jan 04, 2010 2:44 pm
Posts: 23
I've gotten page breaks to work in PdfSharp, but I'm still not managing to get line breaks to behave.

In this particular case, I want to draw the string "Department Name" in 12-point bold underline
Arial, in a space no wider than 90 pt.

So, let's get started:
Code:
XGraphics sizer = XGraphics.FromPdfPage(new PdfPage(new PdfDocument()); // Just a sizer; I'm not drawing anything yet.
sizer.MeasureString("Department Name", new XFont("Arial", 12, XFontStyle.Bold | XFontStyle.Underline));
sizer.MeasureString("Department\nName", new XFont("Arial", 12, XFontStyle.Bold | XFontStyle.Underline));
The former returns (102.7, 13.4). This is too wide, so I replace the space with a carriage return, and try again. The latter returns a width less than 90 pt: (66.7, 27.6). This is good. This is expected. The height approximately doubled, and the width is within the required 90 pt. However, when I go to draw it:
Code:
XGraphics canvas; // initialized appropriately, so I can actually save the document when I'm done.
canvas.DrawString("Department\nName", new XFont("Arial", 12, XFontStyle.Bold | XFontStyle.Underline), XBrushes.Black, 72, 72)
I get this gem:
Attachment:
DepartmentName.PNG
DepartmentName.PNG [ 1.43 KiB | Viewed 35674 times ]
(This is made worse by the string that starts 90 pt to the right; smack on top of the 'm'.)

The obvious issue is the non-existence of the line break, but note also the approximately em-sized space where the "\n" was, and the underlining that disappears.
Using "\r" instead if "\n" is identical, except that the underlining is preserved. (And that MeasureString returns a different value.)
Using "\r\n" adds an em-sized underlined space immediately after the 't', and before the non-underlined space.
Using "\v\n" measures with substantially more vertical space, but again fails draw the text on multiple lines.

What do I need to do to get DrawString to draw in the box that MeasureString says it will?

[0] For the record, I can also handle line breaks for strings like "DepartmentName". "DepartmentNa\nme" doesn't print any better than "Department\nName".


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Wed Jan 06, 2010 4:21 pm 
Offline

Joined: Tue Dec 22, 2009 5:42 pm
Posts: 6
I use a combination of PDFSharp and MigraDoc.

Use the MigraDoc to draw Tables and Paragraphs etc. and then use PDFSharp to do any drawing on the page.

You can add line breaks in a paragraph using :

Paragraph aPara = aTextFrame.AddParagraph();
aPara.AddLineBreak();

- arch


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Wed Jan 06, 2010 8:07 pm 
Offline

Joined: Mon Jan 04, 2010 2:44 pm
Posts: 23
I'm not sure that will work.
Making the report readable requires behaviour that approximately[1] emulates SSRS's HideDuplicates tag[0]. I've got this working with PdfSharp, but I don't see a way to do it with MigraDoc. I did check the documentation for Cell, Row, Column, and Table, but nothing jumped out at me.

[0] In selected columns, cells that have the same content as the previous cell in that column have their content hidden, unless they are in the first row on a page.
[1] Among other things, in SSRS, cells with hidden content can still cause the row to grow vertically. This is ... not desirable.


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Wed Jan 13, 2010 7:55 am 
Offline

Joined: Mon Jan 11, 2010 5:35 pm
Posts: 9
Similar problem....I want to use MigraDoc because of the line breaks in a paragraph, but I need to stikeout the paragraph which I can only do using a PdfSharp drawing. Now I have to position each line which may run longer sometimes because of the variable values in the paragraph.
Would be nice if AddFormattedText() supported Strikeout.


Top
 Profile  
Reply with quote  
 Post subject: Re: PdfSharp line breaks
PostPosted: Fri Jul 25, 2014 9:07 am 
Offline

Joined: Tue Jul 08, 2014 9:28 am
Posts: 12
jro280 wrote:
Similar problem....I want to use MigraDoc because of the line breaks in a paragraph, but I need to stikeout the paragraph which I can only do using a PdfSharp drawing. Now I have to position each line which may run longer sometimes because of the variable values in the paragraph.
Would be nice if AddFormattedText() supported Strikeout.



Hello, I have a similar case with you, I have a PDF file which has a table inside and it across many pages. Some text inside the table cell needed to strikeout, I still have no idea.


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

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 248 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