PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Nov 09, 2024 12:32 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
 Post subject: Embedded table
PostPosted: Tue Apr 23, 2024 11:15 am 
Offline

Joined: Tue Apr 23, 2024 9:50 am
Posts: 4
Hi,
I shall create something like the following:

One header -> it is solved by set the primary header: Section.Headers.Primary

After the header, I need a table with two separated column which are not connect to each other.
This is required because in the first column, there are only two rows, which should be on each page. (Maybe the row.HeadingFormat = true solves it)
The second column shall contains several line of text, it may happen that requires more than one page, not fit on only one.

The requirement is something like the attached picture.
Title, country name and country flag should be in each page, on the right side, the content could be longer than one A4 page size, so page break option is requirement.

Attachment:
File comment: expected_pdf
Képernyőkép 2024-04-23 115946.png
Képernyőkép 2024-04-23 115946.png [ 155.84 KiB | Viewed 37125 times ]


I tried out several approaches, workarounds but none of them worked as expected.

Could you suggest any approach about how could I reach my aim?

Thank you in advance!


Top
 Profile  
Reply with quote  
 Post subject: Re: Embedded table
PostPosted: Tue Apr 23, 2024 11:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1007
Location: CCAA
There is no simple solution.

Create one document for the left column - this will always fit on a single page.
Create one document for the right column, but with an empty left column.

Than create the document in a loop, adding as many pages as required by the right column and repeating the left column on each page.

See the progress bar sample that has a similar loop:
viewtopic.php?f=8&t=3172

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Embedded table
PostPosted: Tue Apr 30, 2024 9:11 am 
Offline

Joined: Tue Apr 23, 2024 9:50 am
Posts: 4
Thank you for your quick response.
Unfortunately, I did not find any related approach which would be helpful for my problem.

Moreover, if I understand well, I should create 3 document

var mainDocument = new Document();
var leftColumDocument = new Document();
var rightColumDocument = new Document();

I create separately the sections for the leftColumn and RightColumn documents. After it I created the related tables.
I filled the leftColumn and rightColumn documents with the required data, but when I tried to render and save the pdf file got the following exception, which I guess relates to the tables on each other:
System.InvalidOperationException : Failed to compare two elements in the array.

I tried to add the left and right column documents to the main document with the following:

mainDocument.Add(countryDataSection!.Clone());
mainDocument.Add(contentSection!.Clone());

Here is the summary of code:


public Document CreateDocument()
{
GlobalFontSettings.FontResolver ??= new FontResolver();

var mainDocument = new Document();

var countryDataDocument = new Document();
var countryDataSection = countryDataDocument.AddSection();
DefineStyles(countryDataDocument);
SetUpPage(countryDataSection);
AddHeader(countryDataSection);
AddFooter(countryDataSection);
CreateCountryData(countryDataSection);

var contentDataDocument = new Document();
var contentSection = contentDataDocument.AddSection();
DefineStyles(contentDataDocument);
SetUpPage(contentSection);
CreateContentData(contentSection);

mainDocument.Add(countryDataSection!.Clone());
mainDocument.Add(contentSection!.Clone());

return mainDocument;
}

Then I create a PdfDocumentRenderer by the mainDocument, and when I call the pdfRenderer.RenderDocument() method, I got the exception above.

What am I doing wrong?

Thank you in advance!


Top
 Profile  
Reply with quote  
 Post subject: Re: Embedded table
PostPosted: Tue Apr 30, 2024 11:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1007
Location: CCAA
mark.kelemen0001 wrote:
Moreover, if I understand well, I should create 3 document

var mainDocument = new Document();
var leftColumDocument = new Document();
var rightColumDocument = new Document();

You need one PdfDocument, one Document for the right column, one document for the left column.
And then you call RenderPage, not RenderDocument, to draw the pages from the "Documents" onto the pages of the "PdfDocument".

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Embedded table
PostPosted: Fri May 03, 2024 7:28 am 
Offline

Joined: Tue Apr 23, 2024 9:50 am
Posts: 4
Thank you for your help! I could reach the expected result! :)


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 6 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group