繁体   English   中英

Itext pdf - 文本向右对齐

[英]Itext pdf - text alignment to right

我正在使用 Itext PDF API 生成 pdf。 我试图让一些文本与 pdf 的右侧对齐。 我尝试了手动间距方法,但由于某种原因不起作用(代码如下所示)。 同时,如果有一种动态的方法会很棒,请!

String dest = "\\location\\";
    PdfWriter writer;

        writer = new PdfWriter(dest);

        // Creating a PdfDcoument
        PdfDocument pdf = new PdfDocument(writer);

        // Creating a Document
        Document document = new Document(pdf);

        // Creating a String
        String para1 = "TEXT";

        //Spacing length
        while (para1.length() < 50) {

              para1 = " " + para1;

            }


        //Creating Paragraphs
        Paragraph paragraph1 = new Paragraph(para1);

        //paragraph1.setAlignment(Element.ALIGN_CENTER);

        //Adding Paragraphs to document
        document.add(paragraph1);

        // Closing the document
        document.close();

提前致谢!

com.itextpdf.layout.element.Paragraphitext7具有方法setTextAlignment 我希望这是你正在寻找的:

...                 
            paragraph1.setTextAlignment(TextAlignment.RIGHT);    
...

我正在使用 com.itextpdf:itextpdf:5.5.10 看起来这些东西已经移动了一点。

    paragraph1.setAlignment(com.itextpdf.text.Element.ALIGN_RIGHT)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM