【问题标题】:Last line of justified right-to-left text should be aligned to right, but is not对齐的从右到左文本的最后一行应与右对齐,但不是
【发布时间】:2019-01-06 22:59:14
【问题描述】:

设置 TextAlignment.JUSTIFIED 时,最后一行没有对齐,这是正确的。但是,对于从右到左的语言(如希伯来语)的文本,最后一行是左对齐,而不是右对齐。

正如您在代码中看到的,我尝试在 Document 对象上设置各种属性,但都没有对问题产生任何影响。

Here is a sample PDF file

String path = "C:\\Users\\davidz\\Desktop\\verylittle.pdf";
PdfWriter writer = new PdfWriter(new FileOutputStream(path));
PdfDocument pdf = new PdfDocument(writer);
pdf.addNewPage();
Document doc = new Document(pdf);
doc.setBaseDirection(BaseDirection.RIGHT_TO_LEFT);
doc.setTextAlignment(TextAlignment.RIGHT);
doc.setHorizontalAlignment(HorizontalAlignment.RIGHT);
JavaItext.loadLicenses("\\\\formit7\\e$\\formit\\ConvertIT\\Resources\\Fonts");
GetFonts fontbank = new GetFonts("C:\\Users\\davidz\\Desktop\\fonts");
PdfFont sanserif = fontbank.getFont("Arial", true);

String hebrew = "כל עוד בלבב פנימה נפש יהודי הומיה ולפאתי מזרח קדימה עין לציון צופיה עוד לא אבדה תקותנו";
Paragraph p = new Paragraph(hebrew);
p.setFont(sanserif);
p.setWidth(180);
p.setBorder(new SolidBorder(1));
p.setTextAlignment(TextAlignment.JUSTIFIED);
p.setFixedLeading(12f);
p.setHeight(50f);
doc.add(p);

doc.close();
pdf.close();

【问题讨论】:

    标签: itext7 text-alignment


    【解决方案1】:

    目前 iText 7.1.5-SNAPSHOT 开发版本中已修复此错误,该修复将在下一个版本中提供。现在的结果如下所示:

    同时,您现在可以使用带有修复程序的开发版本。可以使用以下 Maven 配置从 iText Artifactory 访问它:

    <repositories>
        <repository>
            <id>itext-snapshot</id>
            <name>iText Repository - snapshots</name>
            <url>https://repo.itextsupport.com/snapshot</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>layout</artifactId>
            <version>7.1.5-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>typography</artifactId>
            <version>2.0.3-SNAPSHOT</version>
        </dependency>
    </dependencies>
    

    【讨论】:

      猜你喜欢
      • 2016-08-10
      • 1970-01-01
      • 2023-03-15
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      相关资源
      最近更新 更多