本帖最后由 蹒跚的蜗牛 于 2025-4-3 16:38 编辑
1).业务需求描述:
C1PrintDocument打印时,页脚区距离纸张底部的空白距离是固定的,页脚区的内容如果过长,允许向上增长,但是不能减少下方的空白区的高度,如果页脚区的行数过多,允许与正文区的内容重叠;页脚区的内容的行数是不固定的,是客户自行编辑输入的
2).遇到的问题:
使用C1PrintDocument的PageFooter添加页脚区后,当行数较多时,页脚区的高度会很高,此时C1PrintDocument会自动减少正文区的空间来保证页脚区和正文区的内容不重叠,从而导致正文区自动分页了,能否通过设置什么参数,使得C1PrintDocument类似Excel那样,无论页脚区的高度是多少,都不要自动减少正文区的高度,即使页脚区和正文区的内容重叠到一起也是可以接受的
3).问题截图:
4).相关代码:
a).设置页脚的代码:
private void _pd_PageConfigure(C1PrintDocument sender, PageConfigureEventArgs e)
{
var tagDic = new Dictionary<string, string>()
{
["[PageNo]"] = $"{PageSetup.StartPageNo + e.Page.PageNo - 1}",
["[PageCount]"] = $"{e.Page.PageCount}"
};
var pl = new PageLayout();
pl.PageHeader = CreateHeader(tagDic);
pl.PageFooter = CreateFooter(tagDic); // 设置页脚区
e.PageLayout = pl;
}
//创建页脚
private RenderObject CreatePageFooter(Dictionary<string, string> tagDic)
{
var footerTable = new RenderTable();
var r = 0;
footerTable.Cells[0, 0].SpanCols = 3;
var controlRow = footerTable.Rows[r];
var controlHeight = PageSetup.BottomMargin - PageSetup.FooterMargin;
controlRow.Height = new Unit(controlHeight > 0 ? controlHeight : 0, UnitTypeEnum.Mm);
r = 1;
var footerLeft = RenderFactory.CreateRichText("left");
footerLeft.Rtf = HeaderFooterDeal(PageSetup.PageFooter.LeftValue, tagDic, HorizontalAlignment.Left);
footerLeft.Style.TextAlignVert = AlignVertEnum.Bottom;
footerTable.Cells[r, 0].RenderObject = footerLeft;
var footerCenter = RenderFactory.CreateRichText("center");
footerCenter.Rtf = HeaderFooterDeal(PageSetup.PageFooter.CenterValue, tagDic, HorizontalAlignment.Center);
footerCenter.Style.TextAlignVert = AlignVertEnum.Bottom;
footerTable.Cells[r, 1].RenderObject = footerCenter;
var footerRight = RenderFactory.CreateRichText("right");
footerRight.Rtf = HeaderFooterDeal(PageSetup.PageFooter.RightValue, tagDic, HorizontalAlignment.Right);
footerRight.Style.TextAlignVert = AlignVertEnum.Bottom;
footerTable.Cells[r, 2].RenderObject = footerRight;
return footerTable;
}
b).表格打印时的代码:
_pd.StartDoc();
DataTable = new RenderTable();
DataTable.Style.FlowAlign = FlowAlignEnum.Center;
DataTable.SplitHorzBehavior = SplitBehaviorEnum.SplitIfNeeded;
// 设置正文区的内容
CreateMainTable();
_pd.RenderBlock(DataTable);
_pd.EndDoc();
|