我在复合模式下使用列文本并为其添加段落。 段落具有对齐,左或右。即使右侧对齐段落中的文本行左侧有足够的空间,右对齐时线条的最后一个字符也会被部分裁剪。裁剪的最后一个字符的宽度小于其边界框的xmin和xmax之差。怎么能阻止这种裁剪? 以下是一个例子。
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.log.SysoCounter;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;
public class CroppingSSCCE {
public static void main(String[] args) {
FontFactory.register("MrsEavIta.ttf");
float llx = 0;
float lly = 0;
float urx = 136.93744978164614f;
float ury = 32.86498794759508f;
Rectangle pageSize = new Rectangle(llx, lly, urx, ury);
try {
FileOutputStream baos = new FileOutputStream("CroppingSSCCE.pdf");
Document document = new Document(pageSize);
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfContentByte canvas = writer.getDirectContent();
canvas.getPdfDocument().setPageSize(pageSize);
Paragraph paragraph = new Paragraph();
paragraph.setAlignment(Element.ALIGN_RIGHT);
Font font = FontFactory.getFont("MrsEavesItalic", BaseFont.WINANSI, BaseFont.EMBEDDED, 28, Font.NORMAL, BaseColor.BLACK);
Chunk chunk = new Chunk("Hello T", font);
paragraph.add(chunk);
ColumnText ct = new ColumnText(canvas);
ct.setSimpleColumn(pageSize);
ct.setUseAscender(true);
ct.addElement(paragraph);
ct.go();
document.close();
writer.close();
baos.close();
} catch (Exception de) {
System.out.print("Error: " + de.getMessage());
}
}
}