PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 8:42 am

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
PostPosted: Mon Jan 11, 2010 9:53 pm 
Offline

Joined: Tue Nov 17, 2009 8:24 pm
Posts: 9
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 12, 2010 10:31 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 12, 2010 1:03 pm 
Offline

Joined: Tue Nov 17, 2009 8:24 pm
Posts: 9
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 12, 2010 1:58 pm 
Offline

Joined: Tue Nov 17, 2009 8:24 pm
Posts: 9
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";


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 12, 2010 3:20 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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");

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 12, 2010 4:55 pm 
Offline

Joined: Tue Nov 17, 2009 8:24 pm
Posts: 9
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);


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 13, 2010 10:11 am 
Offline
PDFsharp Guru
User avatar

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

I can't see any obvious errors.

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


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 411 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