PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Left AND Right justify 2 pieces of text on same line in Migr
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1018
Page 1 of 1

Author:  JonJacobs [ Mon Jan 11, 2010 9:53 pm ]
Post subject:  Left AND Right justify 2 pieces of text on same line in Migr

I have a need to add 2 pieces of text in a text frame on the same line. The first piece of text has to be left justified and the second piece of text has to be right justified.

I have no idea how to do this in MigraDoc. DoI create 2 paragraphs that land on the same line? Do I have to create 2 frames that occupy the same space?

??

Thanks,
Jon

Author:  Thomas Hoevel [ Tue Jan 12, 2010 10:31 am ]
Post subject:  Re: Left AND Right justify 2 pieces of text on same line in Migr

I'd use a right-aligned tabulator.
That'll work if the texts are short and will not overlap.

Using two textframes will also work and will allow texts to overlap.

Author:  JonJacobs [ Tue Jan 12, 2010 1:03 pm ]
Post subject:  Re: Left AND Right justify 2 pieces of text on same line in Migr

I tried the two textframes, but for white text on blue backtround, the second text obliterates the first text, so the tabulator must be the way to go. Both pieces of text are short and do not overlap. The second piece is a smaller font size. I haven't been able to find any information on tabulators. How to I add one?

Thanks,

Jon

Author:  JonJacobs [ Tue Jan 12, 2010 1:58 pm ]
Post subject:  Re: Left AND Right justify 2 pieces of text on same line in Migr

I figured out that by "tabulator" you were referring to adding a table to the textframe. 2 columns, 1 row. I made cell[0] left aligned and cell[1] right aligned. I added my paragraphs to the cells. They had the appropriate styes. It sort of works, but for two problems.
1. I get a white break in my blue background which needs to span the width the frame (first line only - the rest of the text frame needs to be white)
2. The column properties and the paragraph styles both specify size 8 in cell[0] and size 7 in cell[1], but I wind up with size 8 in cell[1] anyway. It has to be size 7.
Here is the code:
Code:
            Style bar = mdoc.Styles["bar"];
            bar.Font.Size = 8;
            bar.Font.Name = "Arial";
            bar.ParagraphFormat.LineSpacing = 9;
            bar.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
            bar.Font.Bold = true;
            bar.ParagraphFormat.Shading.Color = reportColor;
            bar.Font.Color = Colors.White;


            Style barr = mdoc.Styles["barr"];
            barr.Font.Size = 7;
            barr.Font.Name = "Arial";
            barr.ParagraphFormat.LineSpacing = 9;
            barr.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
            barr.Font.Bold = true;
            barr.ParagraphFormat.Shading.Color = reportColor;
            barr.Font.Color = Colors.White;
            barr.ParagraphFormat.Alignment = ParagraphAlignment.Right;

...

            Table table = frame.AddTable();
            Column col1 = table.AddColumn();
            col1.Format.Alignment = ParagraphAlignment.Left;
            col1.Format.Font.Bold = true;
            col1.Format.Font.Color = Colors.White;
            col1.Format.Font.Name = "Arial";
            col1.Format.Font.Size = 8;
            col1.Width = "1.3in";

            Column col2 = table.AddColumn();
            col2.Format.Alignment = ParagraphAlignment.Right;
            col2.Format.Font.Bold = true;
            col2.Format.Font.Color = Colors.White;
            col2.Format.Font.Name = "Arial";
            col2.Format.Font.Size = 7;
            col2.Width = "1.6in";

            Row row = table.AddRow();
            par = row.Cells[0].AddParagraph("Physician Information");
            par.Style = "bar";

            string rm = Y.route + "  " + Y.mnemonic;
            par = row.Cells[1].AddParagraph(rm);
            par.Style = "barr";

Author:  Thomas Hoevel [ Tue Jan 12, 2010 3:20 pm ]
Post subject:  Re: Left AND Right justify 2 pieces of text on same line in Migr

You don't need a table, one TabStop is enough.
Sample code (assuming text frame is 10 cm wide):
Code:
style.ParagraphFormat.TabStops.Clear();
style.ParagraphFormat.TabStops.AddTabStop("9.8cm", TabAlignment.Right);

Use AddTab to insert the TabStop:
Code:
paragraph.AddText("left text");
paragraph.AddTab();
paragraph.AddText("right text");

Author:  JonJacobs [ Tue Jan 12, 2010 4:55 pm ]
Post subject:  Re: Left AND Right justify 2 pieces of text on same line in Migr

Thanks!

That works much better. I still can't get the 2 different font sizes. I figured I would use AddFormattedText instead of AddText so I could get the second piece of text in a different font size, but I still get font size 8 on both pieces. Here is my code. Maybe you can spot what I have wrong.

Code:
           
            Paragraph par;
            TextFrame frame = sec.AddTextFrame();
            frame.Left = h.frLeft2;
            frame.Top = h.frTop;
            frame.Width = h.frWidth;
            frame.Height = h.frHeight;
            frame.RelativeHorizontal = RelativeHorizontal.Margin;
            frame.RelativeVertical = RelativeVertical.Page;
            par = frame.AddParagraph("Physician Information");
            par.Style = "bar";
            string rm = Y.route + " " + Y.mnemonic;

            bar.ParagraphFormat.TabStops.Clear();
            bar.ParagraphFormat.AddTabStop(h.frWidth, TabAlignment.Right);
            par.AddTab();
            Font font7 = new Font("Arial", "7pt");
            par.AddFormattedText(rm, font7);

Author:  Thomas Hoevel [ Wed Jan 13, 2010 10:11 am ]
Post subject:  Re: Left AND Right justify 2 pieces of text on same line in Migr

Hi!

I can't see any obvious errors.

Please check the MDDDL file.
http://www.pdfsharp.net/wiki/MigraDocDDL.ashx

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/