开发者

Text overlaping problem using itext for generating a pdf

开发者 https://www.devze.com 2023-03-05 06:57 出处:网络
hi everyone i have a header text(ARTIST Biography(Continue)) in my pdf file generated by using itext(Java).where \'ARTIST\' and \'(Continue)\' are static text \'Biography\' is a dynamic text it will b

hi everyone i have a header text(ARTIST Biography(Continue)) in my pdf file generated by using itext(Java).where 'ARTIST' and '(Continue)' are static text 'Biography' is a dynamic text it will be varied with respect to the content fetched from xml.My problem is while the dynamic text length is too long it will overlap the '(continue)' text.How can i set the dynamic text length with respect to the nearest static text'(Continue)'.please reply Thanks in advance

My code for displaying the header text is (ARTIST Biography(Continue)) written bellow

PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        cb.setFontAndSize(bf, 18);
        cb.beginText();
        cb.setColorFill(Color.BLACK);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT,"ARTIST", document.left(), document.top() + 20  , 0);
        cb.resetRGBColorFill();
        cb.endText();
        cb.beginText();
        cb.setColorFill(Color.RED);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, strBiography, document.left() + 70, document.top() + 20, 0);
        cb.resetRGBColorFill();
        cb.endText();
        cb.beginText();
        cb.setColorFill(Color.BLACK);
        cb.showTe开发者_开发知识库xtAligned(PdfContentByte.ALIGN_LEFT,"(Continue)", document.left()+90, document.top() + 20  , 0);
        cb.resetRGBColorFill();
        cb.endText();
        cb.stroke();


You can create Chunk with the right font and content of strBiography and on the Chunk call getWidthPoint to now it's size in points, you'll have about the length of your strBiography when added to the doc and can calculate the position of "(Continue)"

0

精彩评论

暂无评论...
验证码 换一张
取 消