为有中文需求的客户提供多渠道中文技术支持.

Wed Feb 22, 2023 3:16 am

正文的上面部分,被标题覆盖掉了,请问一下,应该怎么设置才不会被覆盖,在不改变正文和标题格式的情况下。
标题设置
Code: Select all
Paragraph para2 = sec.addParagraph();
                TextRange tr2 = para2.appendText(title1);
                tr2.getCharacterFormat().setFontSize(22);
                tr2.getCharacterFormat().setBold(true);
                tr2.getCharacterFormat().setItalic(false);
                tr2.getCharacterFormat().setFontName("黑体");
                para2.applyStyle(BuiltinStyle.Heading_2);
                //悬挂缩进 1cm
                //单位转换 cm->point
                PdfUnitConvertor convertor2 = new PdfUnitConvertor();
                float distance2 = convertor2.convertUnits(1f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Centimeter);
                para2.getFormat().setFirstLineIndent(-distance2);
                para2.getFormat().setLeftIndent(distance2);
                //间距 段前 段后
                para2.getFormat().setBeforeAutoSpacing(false);
                para2.getFormat().setBeforeSpacing(30);
                para2.getFormat().setAfterAutoSpacing(false);
                para2.getFormat().setAfterSpacing(8);
                //行距 单倍行距 1倍
                para2.getFormat().setLineSpacing(12f);
                //对齐方式 两端对齐
                para2.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);

正文是由HTML转换而成,正文的设置
Code: Select all
Paragraph para = sec.addParagraph();
        para.appendHTML(content);
        para.getFormat().setHorizontalAlignment(HorizontalAlignment.Justify);//设置两端对齐
        para.getFormat().setLineSpacingRule(LineSpacingRule.Multiple);
        para.getFormat().setLineSpacing(1.4f);
        para.getFormat().setBeforeSpacing(3f);//设置间距 段前 3磅
        para.getFormat().setBeforeAutoSpacing(false);
        para.getFormat().setAfterSpacing(3f);//设置间距 段后 3磅
        para.getFormat().setAfterAutoSpacing(false);
        // 设置首行缩进
        para.getFormat().setFirstLineIndent(15f);

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

Wed Feb 22, 2023 10:20 am

您好,

感谢您的留言。
根据您提供的代码来看,您在将cm转pt时代码出错,如下面截图:
正确的代码如下:
Code: Select all
PdfUnitConvertor convertor2 = new PdfUnitConvertor();
float distance2 = convertor2.convertUnits(1f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to 中文技术支持

cron