利用ITextSharp生成PDF时,想在每个页面的下方显示一段文字,决定采用页脚的方式实现,但发现将文字作为参数传入Phrase,然后指定其为document的Footer,文字无法显示,或者只出现了最后两个字,百思不得其解,后来经同事提示,猜测可能是Phrase的某些属性造成的。改用Paragraph对象,发现问题解决。
Paragraph phfooter = new Paragraph(10f, strpagefooter, ChHeadBold09);
phfooter.Alignment = Element.ALIGN_LEFT;
phfooter.SpacingBefore = 20f;
HeaderFooter footer = new HeaderFooter(phfooter, false);
footer.Border = Rectangle.NO_BORDER;
footer.Left = 5;
footer.Right = 5;
phfooter.Alignment = Element.ALIGN_LEFT;
phfooter.SpacingBefore = 20f;
HeaderFooter footer = new HeaderFooter(phfooter, false);
footer.Border = Rectangle.NO_BORDER;
footer.Left = 5;
footer.Right = 5;
document.Footer = footer;
页脚设置时要特别注意,在document对象open之前进行设置,不然设置的页脚将会从第二页开始生效。