PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Aug 24, 2025 11:19 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Aug 14, 2025 3:53 pm 
Offline

Joined: Thu Aug 14, 2025 3:27 pm
Posts: 2
Hi,

I am new to the MIgrDoc forum...honestly...new to using pdfSharp / MigraDoc altogether.
I am creating a pricing report that adds table sections to a document dynamically based on user input criteria.

The data part works fine....the datatables are used to create the Table sections dynamically and each Table section can have different columns.
There are 2 columns that are constants in each Table regardless of the data....an Item Product Code and its description, so I set the proportional width of thos 2 columns as static .
I am trying to take the full table section width - LeftMargin - minus right margin and use that as the available Table Section width...
I then use that to get the widths for the Item Code and Description columns based on the available width
To get the remaining column widths, i subtract the first 2 columns proportional widths and then divide the remaining width by the number of remaining columns to get the remaining columns proportionate width....

In my mind that should work but not in MIgra Doc....when I execute, the columns are all squeezed on top of one another...

here is my code snippet that adds the columns to the Pdf Table section and assigns the column widhts based on the proportions calculated....

tableSection.PageSetup = reportSection.PageSetup.Clone();
tableSection.PageSetup.PageFormat = PageFormat.Letter;
tableSection.PageSetup.LeftMargin = Unit.FromInch(0.125);
tableSection.PageSetup.RightMargin = Unit.FromInch(0.125);
tableSection.PageSetup.BottomMargin = Unit.FromInch(0.5);
double availableContentWidth = tableSection.PageSetup.PageWidth.Point - tableSection.PageSetup.LeftMargin.Point - tableSection.PageSetup.RightMargin.Point;
//double availableContentWidth = reportSection.PageSetup.PageWidth.Point - reportSection.PageSetup.LeftMargin.Point - reportSection.PageSetup.RightMargin.Point; // 8inches is 576 points

double colItemIdRatio = 0.115;
double colItemDescRatio = 0.135;
double colRemainRatio = (1 - colItemIdRatio - colItemDescRatio) / (numberOfColumns - 2);
Table table = tableSection.AddTable();
table.Borders.Width = 0.25; // Example border setting

foreach (DataColumn dtColumn in dataTable.Columns)
{
//column.Format.Alignment = ParagraphAlignment.Left; // Default alignment

double columnWidth;
if (dtColumn.ColumnName.Contains("item_id"))
{
columnWidth = availableContentWidth * colItemIdRatio;
//columnWidth = Unit.FromInch(1.05);
}
else if (dtColumn.ColumnName.Contains("item_desc"))
{
columnWidth = availableContentWidth * colItemDescRatio;
//columnWidth = Unit.FromInch(1.45);
}
else
{
columnWidth = availableContentWidth * colRemainRatio;
//columnWidth = Unit.FromInch(0.4);
}
//Column column = table.AddColumn(columnWidth);
table.AddColumn(Unit.FromPoint(columnWidth));
}


The commented out code works because I am assigning an absolute width, but the other code causes the issue I described above...and I'm not entirely sure why at this point.
I have read the GitHub documentation for MigrDoc and creating Tables, and I have tried several differnat proportiional type calculation approaches that all end in the same outcome.

I am really hoping that someone can point me in the right direction as to why MigraDoc is behaving this way....what am I missing here.
I can provide more of the source code if necessary...I just assumed that I provided the most relevant piece of the puzzle.

Regards,

Brad


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 15, 2025 1:28 pm 
Offline
User avatar

Joined: Thu Mar 06, 2025 10:43 am
Posts: 5
bradvan71 wrote:
I can provide more of the source code if necessary...I just assumed that I provided the most relevant piece of the puzzle.
You can provide a MDDDL file containing such a table. One table with a total of three columns should be enough.

Nothing obviously wrong with your code snippet.

Submitting a complete VS solution is sometimes more helpful than just showing snippets, especially if the real issue is not covered by the snippets.


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 22, 2025 4:40 pm 
Offline

Joined: Thu Aug 14, 2025 3:27 pm
Posts: 2
Hi,

There are more than 3 columns to the tables...the first 2 always being constant which contain an item code and a item description.

so if the table section is set as Letter sized widht less margins for left and right...columns 1 and 2 are set as a proportion of that available width...the remsaining columns would share the remaining available widht based on the number of columns which could vary depending on the DataTable in the DataSet..

I am trying to make those remaining column widths be dynamic based on remaining available widht / remaining number of columns.

Unless I am missing something in my readings of what the MDDDL file does, I'm not sure it will help.

I'm not understanding what MigraDoc is doing under the hood when creating a table section as I am and using proportionate columns widths...it doesn't seem to like how I have contained the math inside my loop to create the Table columns in the Table section.

Regards,

Brad


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

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 60 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