I'm using MigraDoc to create letters in PDF for batch printing. That means I have multiple businesses that need to be notified for listing approval. I have created a template with generic information and I'm filling the details of the letter for each business in a foreach loop like this:
public TemplateClass(string title, string subject, string author, string memo_field)
{
try
{
//---------------------------------------------------
// Set up the document and section
//--------------------------------------------------
_document = new Document();
_section = new Section();
//--------------------------------------------------------------
// Define the margins, style
//--------------------------------------------------------------
this.DefineBorder();
this.DefineStyle(_document);
this.FillHeaderAndFooter(memo_field);
}
catch { }
}
private void FillHeaderAndFooter(string memo_field)
{
//------------------------------------------------
// Add the main section of the document
//-----------------------------------------------------
this._section = this._document.AddSection();
{
this._section.PageSetup.Orientation = Orientation.Portrait;
this._section.PageSetup.PageFormat = PageFormat.Letter;
this._section.PageSetup.OddAndEvenPagesHeaderFooter = true;
//-----------------------------------------------
// Add the header
//-----------------------------------------------
Image primaryImage = this._section.Headers.Primary.AddImage(Image.png");
primaryImage.Height = "4.0cm";
primaryImage.LockAspectRatio = true;
primaryImage.RelativeVertical = RelativeVertical.Line;
primaryImage.RelativeHorizontal = RelativeHorizontal.Margin;
primaryImage.Top = ShapePosition.Top;
primaryImage.Left = ShapePosition.Center;
primaryImage.WrapFormat.Style = WrapStyle.Through;
//------------------------------------------------
// Add the header to the section
//------------------------------------------------
this._section.Headers.Primary.Add(this.Header());
this._section.Headers.EvenPage.Add(this.Header());
this._section.Footers.Primary.Add(this.Footer());
this._section.Footers.EvenPage.Add(this.Footer());
}
}
public void GenerateLetters()
{
template = new TemplateClass("", "", "", "Business Letter");
{
int i = 0;
base.DocumentName = "Business Letter";
var businesses = new List<Business>() { new Business() { ID=333, Name="XYZ", Address = "123 Main St" }, new Business() { ID=666, Name="PQR", Address="123 Main St"}}
foreach (var business in businesses)
{
template.ReportSection.Add(AddBusinessInfo(business));
template.ReportSection.Add(FillTopSection());
template.ReportSection.Add(FillMessage());
template.ReportSection.Add(FillDetails(business));
template.ReportSection.Add(FillBottomSection());
template.ReportSection.Add(FillSignature());
if (i != businesses.Count)
template.ReportSection.AddPageBreak();
i++;
}
}
I am not sharing the code for some of the private methods that are called here. FillDetails(business) is a Table that could have one row or multiple rows. This table information and the content below it is pushed over to next page that has header and it overlaps on it.
I can either skip the the header and footer information from second page onwards for each business or avoid the overlap with header and somehow keep the body of the letter to be static size.