有关showTextAligned(iTextPdf)的问题

时间:2013-12-05 09:24:32

标签: java pdf-generation itext

我尝试插入一个包含Column Text的字符串,但它给了我一个错误:

  

java.lang.ArrayIndexOutOfBoundsException:-14667

在ColumnText.class中 - > showTextAligned(...)我看到了:

switch (alignment) {
            case Element.ALIGN_LEFT:
                llx = 0;
                urx = 20000;
                break;
            case Element.ALIGN_RIGHT:
                llx = -20000;
                urx = 0;
                break;
            default:
                llx = -20000;
                urx = 20000;
                break;
        }

这意味着列必须具有宽度和高度= 20 000.如果我想使用较小的文档(即560px x 300px),我该怎么办?

完整堆栈跟踪是:

  

java.lang.ArrayIndexOutOfBoundsException:-14667 at   com.sun.pdfview.font.ttf.GlyfTable.getGlyph(GlyfTable.java:57)at at   com.sun.pdfview.font.TTFFont.renderCompoundGlyph(TTFFont.java:248)at at   com.sun.pdfview.font.TTFFont.getOutline(TTFFont.java:177)at   com.sun.pdfview.font.CIDFontType2.getOutline(CIDFontType2.java:270)     在com.sun.pdfview.font.OutlineFont.getGlyph(OutlineFont.java:130)     在com.sun.pdfview.font.PDFFont.getCachedGlyph(PDFFont.java:308)at at   com.sun.pdfview.font.PDFFontEncoding.getGlyphFromCMap(PDFFontEncoding.java:155)     在   com.sun.pdfview.font.PDFFontEncoding.getGlyphs(PDFFontEncoding.java:115)     在com.sun.pdfview.font.PDFFont.getGlyphs(PDFFont.java:274)at   com.sun.pdfview.PDFTextFormat.doText(PDFTextFormat.java:269)at at   com.sun.pdfview.PDFParser.iterate(PDFParser.java:752)at   com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)at at   java.lang.Thread.run(Thread.java:744)

我的代码是:

        Document document = null;
    document = new Document(new Rectangle(LABEL_WIDTH*LABEL_RESOLUTION, LABEL_HEIGHT*LABEL_RESOLUTION)); 

    long dateTime = new Date().getTime();
    File pdfTemp = new File(PDF_TEMP_FOLDER, String.valueOf(dateTime) + ".pdf");
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfTemp));

    document.open();
    PdfContentByte cb = writer.getDirectContent();
BaseFont font = BaseFont.createFont("/ARIALUNI.TTF",
            BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);


    Font arabicFont = new Font(font);



    ColumnText columnText = new ColumnText(cb);
    columnText.setSimpleColumn(0, 0, LABEL_WIDTH*LABEL_RESOLUTION, LABEL_HEIGHT*LABEL_RESOLUTION); 
    columnText.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    Phrase phrase = new Phrase(nameVisitor + "22", arabicFont);
    columnText.addElement(phrase);
    columnText.go();
document.close();
    writer.close();

0 个答案:

没有答案