PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 12:47 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
PostPosted: Wed Feb 13, 2008 7:57 am 
Offline

Joined: Wed Feb 13, 2008 7:42 am
Posts: 2
I can't center a table in a page. I insert two paragraph: one for logo, one for title and then a table with 2 columns, all centered in the page but the property table.Format.Alignment = ParagraphAlignment.Center not center the table. Where is the problem? here my code, thanks!

// Add a paragraph to the section
Paragraph logoParagraph = section.AddParagraph();
Paragraph logotextParagraph = section.AddParagraph();

// Add some text to the paragraph
logoParagraph.Format.Alignment = ParagraphAlignment.Center;
MigraDoc.DocumentObjectModel.Shapes.Image logo = logoParagraph.AddImage(Server.MapPath("/Account/logobmp.BMP"));
logo.Height = "60pt";
logo.LockAspectRatio = true;

logotextParagraph.Format.Alignment = ParagraphAlignment.Center;
logotextParagraph.AddFormattedText("Modulo Account", boldFont);
logotextParagraph.Format.SpaceBefore = "1cm";
logotextParagraph.Format.SpaceAfter = "1cm";

// Create the item table
MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable();
table.Format.Alignment = ParagraphAlignment.Center;
table.Borders.Width = 0.5;
table.Borders.Left.Width = 0.5;
table.Borders.Right.Width = 0.5;

MigraDoc.DocumentObjectModel.Tables.Column column;

// Before you can add a row, you must define the columns
column = table.AddColumn();
column.Width = "2cm";
column = table.AddColumn();
column.Width = "5cm";


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 18, 2008 3:10 pm 
Offline

Joined: Wed Feb 13, 2008 7:42 am
Posts: 2
There is another method or tecnique for center a table?
table.Format.Alignment = ParagraphAlignment.Center doesn't work.


Top
 Profile  
Reply with quote  
 Post subject: Table alignment
PostPosted: Fri Mar 14, 2008 1:13 am 
Offline

Joined: Fri Mar 14, 2008 1:05 am
Posts: 2
Could you resolve this issue? I've same problem.
table.Format.Alignment = ParagraphAlignment.Center doesn't work because this property is for cells alignment.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 14, 2008 2:38 am 
Offline

Joined: Fri Mar 14, 2008 1:05 am
Posts: 2
I found a solution for this issue.

TextFrame addressFrame;
addressFrame = section.AddTextFrame();
addressFrame.LineFormat.Width = 0.5; //Only for visual purposes
addressFrame.Height = "15.0cm";//any number
addressFrame.Width = "10.0cm";//sum of col widths
addressFrame.Left = ShapePosition.Center;
addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;//irrelevant
addressFrame.Top = "10.0cm";//irrelevant
addressFrame.RelativeVertical = RelativeVertical.Page;//irrelevant

Table table = addressFrame.AddTable();
//Here other table parameters

Enjoy


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 09, 2013 5:20 pm 
Offline

Joined: Fri Aug 09, 2013 8:42 am
Posts: 2
Thanks chf - exactly what I was looking for! :D


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 01, 2018 7:54 pm 
Offline
Supporter

Joined: Sat Oct 18, 2008 4:15 pm
Posts: 50
Worked like this (to horizontaly center table with chart):

Code:
TextFrame addressFrame;
            addressFrame = document.LastSection.AddTextFrame();
            addressFrame.Height = "6.0cm";//any number
            addressFrame.Width = "9.0cm";//sum of col widths
            addressFrame.Left = ShapePosition.Center;
           
            var table = addressFrame.AddTable();


would be happier if I did not have to specify dimensions, but so far so good


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 01, 2018 8:13 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
gastan wrote:
Worked like this (to horizontally center table with chart)
Putting the table into a TextFrame prevents the table from breaking across multiple pages.

For a clean indentation that works across pagebreaks, use
Code:
table.Rows.LeftIndent

Knowing the width of the page and the width of the table, it is simple to calculate the left indent needed to centre the table.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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