PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Embedded table
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4584
Page 1 of 1

Author:  mark.kelemen0001 [ Tue Apr 23, 2024 11:15 am ]
Post subject:  Embedded table

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 25745 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!

Author:  TH-Soft [ Tue Apr 23, 2024 11:35 am ]
Post subject:  Re: Embedded table

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

Author:  mark.kelemen0001 [ Tue Apr 30, 2024 9:11 am ]
Post subject:  Re: Embedded table

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!

Author:  TH-Soft [ Tue Apr 30, 2024 11:35 am ]
Post subject:  Re: Embedded table

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".

Author:  mark.kelemen0001 [ Fri May 03, 2024 7:28 am ]
Post subject:  Re: Embedded table

Thank you for your help! I could reach the expected result! :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/