c# - MigraDoc 文本溢出到下一页页眉
问题描述
我正在使用 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) 是一个可以有一行或多行的表。这个表格信息和它下面的内容被推送到具有标题的下一页并且它重叠在上面。
我可以从每个业务的第二页开始跳过页眉和页脚信息,或者避免与页眉重叠,并以某种方式将信函的正文保持为静态大小。
解决方案
使用 MigraDoc 时,您必须设置一个足够大的顶部边框以容纳标题。如果标头大于保留区域,则标头和正文可能会重叠,而 MigraDoc 无法阻止这种情况。
仅在第一页上有标题是另一种选择。
推荐阅读
- javascript - 我可以将 className 作为道具传递给 ReactJS 中的 StyledComponent 吗?
- zsh - 有没有办法在 tmux new 命令上加载 .zprofile 之类的文件?
- python - 根据同一属性的多个值过滤查询集
- java - Eclipse 为什么以及何时将 Maven 依赖项放在 CLASSPATH 中而不是 MODULEPATH 中?
- python - 使用 python 解析 yaml 文件以查找重复值
- docker - 启动 spring-boot 和 docker 时出现 x509 SSL 错误
- python - 加快 Python 中的嵌套 for 循环处理
- ggplot2 - ggplot2:将因子变量传递给 facet_wrap
- python - 根据 df.groupby 中的值对类别进行分组
- coq - Coq 中严格正则表达式与格式错误的正则表达式