【发布时间】:2018-08-13 17:25:05
【问题描述】:
我正在使用 MigraDoc 在 PDF 中创建字母以进行批量打印。这意味着我有多家企业需要通知上市批准。我创建了一个包含通用信息的模板,并在 foreach 循环中为每个企业填写了信函的详细信息,如下所示:
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++;
}
}
我不会分享这里调用的一些私有方法的代码。 FillDetails(business) 是一个可以有一行或多行的表。此表格信息及其下方的内容被推送到具有标题的下一页并在其上重叠。
我可以从第二页开始跳过每个业务的页眉和页脚信息,或者避免与页眉重叠并以某种方式将信函的正文保持为静态大小。
【问题讨论】: