PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 15, 2024 6:55 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Tabstop problem
PostPosted: Fri Dec 03, 2010 10:24 am 
Offline

Joined: Wed May 26, 2010 9:14 am
Posts: 13
I'm trying to output some text that consist of a centred para header in bold followed by a blank line followed by some 2 or 3 lines of para text. I want the whole thing kept together on the same page. Below is the code I'm using. It works Ok except that the para header does not centre. The tab is applied as though it were a left align. Any ideas?

style = doc.Styles.AddStyle("bold", "Normal");
style.Font.Bold = true;

style = doc.Styles.AddStyle("leftalign", "Normal");
style.ParagraphFormat.Alignment = ParagraphAlignment.Left;
style.Font.Bold = false;

para = section.AddParagraph();
para.Format.KeepTogether = true;
para.Format.AddTabStop(doc.DefaultPageSetup.PageWidth / 2, MigraDoc.DocumentObjectModel.TabAlignment.Center);
para.AddFormattedText("\tPara header", "bold");
para.AddText("\r\n\r\n");
para.AddFormattedText("some text for 2 or lines", "leftalign");


Top
 Profile  
Reply with quote  
 Post subject: Re: Tabstop problem
PostPosted: Mon Dec 06, 2010 11:19 am 
Offline
PDFsharp Guru
User avatar

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

I haven't tried your snippet, but normally Tabs work.

Instead of calling
Code:
para.Format.AddTabStop(...)

I'd call
Code:
para.Format.TabStops.ClearAll();
para.Format.TabStops.AddTabStop(...);


If that doesn't help, try
Code:
para.AddTab();
para.AddFormattedText("Para header", "bold");

instead of
Code:
para.AddFormattedText("\tPara header", "bold");


Using "\t" should work but I know that AddTab() does work ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Tabstop problem
PostPosted: Mon Dec 06, 2010 12:51 pm 
Offline

Joined: Wed May 26, 2010 9:14 am
Posts: 13
Hi Thomas,
I've tried the changes you suggest but it still left aligns the text at the tab instead of centering it.
Dave


Top
 Profile  
Reply with quote  
 Post subject: Re: Tabstop problem
PostPosted: Mon Dec 06, 2010 1:03 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi, Dave,

If you provide a MigraDoc DDL file (can be attached in a ZIP file) I'll look at it.

See here:
http://www.pdfsharp.net/wiki/MigraDocDDL.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Tabstop problem
PostPosted: Mon Dec 06, 2010 1:27 pm 
Offline

Joined: Wed May 26, 2010 9:14 am
Posts: 13
Thomas,
before you do that, I may have a clue. If I change the calculation of the mid pt for the tab
from
doc.DefaultPageSetup.PageWidth / 2
to
(doc.DefaultPageSetup.PageWidth / 2) - doc.DefaultPageSetup.LeftMargin
it looks like it centres correctly. Are the origins of the tab positions from the edge of the page or from the left margin?
Dave


Top
 Profile  
Reply with quote  
 Post subject: Re: Tabstop problem
PostPosted: Mon Dec 06, 2010 1:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
DaveR wrote:
Are the origins of the tab positions from the edge of the page or from the left margin?

From the left margin (similar to Word).

Didn't pay attention to it but now that you mention it. :oops:

So: problem solved, I presume.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Tabstop problem
PostPosted: Mon Dec 06, 2010 2:15 pm 
Offline

Joined: Wed May 26, 2010 9:14 am
Posts: 13
Yes, thanks.
So, just to confirm, to get the centre of the printable area would be:

(doc.DefaultPageSetup.PageWidth - doc.DefaultPageSetup.LeftMargin - doc.DefaultPageSetup.RightMargin) / 2

Dave


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

All times are UTC


Who is online

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