« Return to Thread: How to calculate text-height when using PDFContentByte?

How to calculate text-height when using PDFContentByte?

by pocketom :: Rate this Message:

Reply to Author | View in Thread

I'm using PDFContentByte to build a function graph object. To generate the x-axis scala I use cb.getEffectiveStringWidth(string, false); which works pretty good here. But to create units for the y-axis I need to know in advance the heigth of a string in advance to calculate how many units I want to print.


Here is a little example I've prepared:

public static void main(String[] args) throws InterruptedException
{
        int fontsize = 12;
   
        try
        {
                BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

                cb.setFontAndSize(bf, fontsize);
        }
        catch (IOException e)
        {
                e.printStackTrace();
        }
               
        cb.moveTo(250, 600);
        cb.lineTo(250, 600+fontsize); // HOW TO DRAW THE LINE WITH TEH SAME HEIGHT AS MY BASEFONT?
        cb.stroke();
               
        cb.beginText();
        cb.moveText(252, 600);
        cb.showText("HELLO");
        cb.endText();
}


How can I detect the effective height of the text to draw a vertical line with same height as the text when I want to work with the PDFContentbyte?

 « Return to Thread: How to calculate text-height when using PDFContentByte?