PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 24, 2024 1:29 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Mar 19, 2013 2:33 pm 
Offline

Joined: Tue Mar 19, 2013 2:25 pm
Posts: 5
Hi,

I'm using MigraDoc for the first time and of course I have some questions ;).

1. I like to create a header with two different texts in the same line.
One text is a changing value from our database and should be left aligned and the other
text is constand and should be right aligned and use another font. How can I do this (not the db-stuff only the printing of two differntly formated texts in the same line ;))?

2. The main body of my document contains a table (Table table = section.AddTable();)
This table seems to be centered on all pages but I want it to be aligned to the top.
How can I achieve this?

Many thanks in advance :).


Last edited by Rahvin on Fri Mar 22, 2013 2:55 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: some noob questions
PostPosted: Wed Mar 20, 2013 9:53 am 
Offline
PDFsharp Guru
User avatar

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

Re 1:
Remove all tab stops, then add a single right-aligned tab stop for the right edge. Then use a single paragraph, add the left-aligned text, a tab stop, then the right-aligned text.
This works fine as long as the whole text fits a single line (use AddFormattedText to have differing formats).

Re 2:
Tables are top-aligned. Check the top margin of your section.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: some noob questions
PostPosted: Wed Mar 20, 2013 3:17 pm 
Offline

Joined: Tue Mar 19, 2013 2:25 pm
Posts: 5
Hi and thanks for you answer.

1.
Could you please post some code? I don't quite understand what you mean.
This is my code so far:
Code:
         
                    Paragraph pa = new Paragraph();
                    pa.Add(new Text(p.Hersteller));
                    pa.Format.Font.Size = 10;
                    pa.Format.Font.Bold = true;

                    section.Headers.Primary.Add(pa);


2. Ok, it works now. It seemed to be an issue with some table-row-blocks I kept together with KeepWith


Top
 Profile  
Reply with quote  
 Post subject: Re: some noob questions
PostPosted: Wed Mar 20, 2013 4:17 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Here's a code snippet that adds the text:
Code:
paragraph = section.Footers.Primary.AddParagraph();
FormattedText ft = paragraph.AddFormattedText("AppName", TextFormat.Bold);
ft.Font.Size = 6;
paragraph.AddTab();
paragraph.AddPageField();
paragraph.AddTab();
ft = paragraph.AddFormattedText("More info (bold) " + ApplicationSettings.Berichtsjahr, TextFormat.Bold);
ft.Font.Size = 6;
ft = paragraph.AddFormattedText(" and more info (not bold)", TextFormat.NotBold);
ft.Font.Size = 6;

We use three tab stops.

The code that sets the tab stops:
Code:
Style style;
style = document.Styles[StyleNames.Footer];
style.ParagraphFormat.TabStops.Clear();
style.ParagraphFormat.AddTabStop(center.ToString(CultureInfo.InvariantCulture) + "cm", TabAlignment.Center);
style.ParagraphFormat.AddTabStop(paperwidth.ToString(CultureInfo.InvariantCulture) + "cm", TabAlignment.Right);


You don't need the "center" tab stop, so only use a single AddTab().

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: some noob questions
PostPosted: Fri Mar 22, 2013 11:16 am 
Offline

Joined: Tue Mar 19, 2013 2:25 pm
Posts: 5
Vielen Dank :)!


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

All times are UTC


Who is online

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