PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Tabstop problem https://forum.pdfsharp.net/viewtopic.php?f=2&t=1459 |
Page 1 of 1 |
Author: | DaveR [ Fri Dec 03, 2010 10:24 am ] |
Post subject: | Tabstop problem |
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"); |
Author: | Thomas Hoevel [ Mon Dec 06, 2010 11:19 am ] |
Post subject: | Re: Tabstop problem |
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 ... |
Author: | DaveR [ Mon Dec 06, 2010 12:51 pm ] |
Post subject: | Re: Tabstop problem |
Hi Thomas, I've tried the changes you suggest but it still left aligns the text at the tab instead of centering it. Dave |
Author: | Thomas Hoevel [ Mon Dec 06, 2010 1:03 pm ] |
Post subject: | Re: Tabstop problem |
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 |
Author: | DaveR [ Mon Dec 06, 2010 1:27 pm ] |
Post subject: | Re: Tabstop problem |
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 |
Author: | Thomas Hoevel [ Mon Dec 06, 2010 1:59 pm ] |
Post subject: | Re: Tabstop problem |
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. ![]() So: problem solved, I presume. |
Author: | DaveR [ Mon Dec 06, 2010 2:15 pm ] |
Post subject: | Re: Tabstop problem |
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 |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |