Creating a master detail table from a List<Model> in PDF report with PDFsharp or ITextSharp

966 views Asked by At

I just want to a create a report with a table look like this :

enter image description here

Day, Date, and Movement are properties from DailyProgram model. Here's my DailyProgram class :

public class DailyProgram {
        public DailyProgram(int day, DateTime date) {
            this.Day = day;
            this.Date = date;
            this.TourDestinations = new List<TourDestination>();
            this.MovementSummary = new MovementSummary();
            this.Movements = new List<Movement>();
        }
        public int Day { get; set; }
        public DateTime Date { get; set; }
        public ICollection<TourDestination> TourDestinations { get; set; }
        public MovementSummary MovementSummary { get; set; }
        public ICollection<Movement> Movements { get; set; }

        public class TourDestination {
            public TourDestination(string destination) {
                this.Destination = destination;
                this.AttractionSummary = new List<AttractionSummary>();
                this.TransportationSummary = new List<TransportationSummary>();
            }
            public string Destination { get; set; }
            public AccommodationSummary AccommodationSummary { get; set; }
            public ICollection<TransportationSummary> TransportationSummary;
            public ICollection<AttractionSummary> AttractionSummary;
        }
    }

And the records in Movements section are from ICollection<Movement> Movements. Here my Movement class :

public class Movement
    {
        [DataType(DataType.DateTime)]
        public DateTime DateTime { get; set; }

        public int SeqNumber { get; set; }

        public string MovementName { get; set; }

        public string MovementDescription { get; set; }

        public int Duration { get; set; }

        public int ServiceItemId { get; set; }            

        public string Destination { get; set; }

        public MovementItem Item { get; set; }
    }

My Question is: I already try to find a tutorial to make a PDF report with the concept of Master-detail that I explain above in Google, but I have not found a tutorial yet. Is there any source or documentation from ITextSharp or PDFsharp to make PDF report with master detail but from list in code, not from database?

What I ever tried is Using subreport in Microsoft.Report.Viewer (RDLC). In RDLC I tried to Invoke the EventHandler in WEB API, but without success.

UPDATE

So far, I choose IText 7 for solve this question. And I solved this question by using PdfPTable and PdfPCell from IText 7.

1

There are 1 answers

1
I liked the old Stack Overflow On

PDFsharp does not support tables. You can create tables by drawing text and lines around it.

MigraDoc comes bundled with PDFsharp. MigraDoc supports tables.

The Invoice sample does not demonstrate master/detail views, but shows how to create a table and also shows how to use MergeRight and MergeDown.
http://www.pdfsharp.net/wiki/Invoice-sample.ashx