public float getStringWidth(String text) throws IOException
    {
        byte[] bytes = encode(text);
        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
        
        float width = 0;
        while (in.available() > 0)
        {
            int code = readCode(in);
            width += getWidth(code);
        }
        
        return width;
    }
@Test
    void testSoftHyphen() throws IOException
    {
        String text = "- \u00AD";
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (PDDocument doc = new PDDocument())
        {
            PDPage page = new PDPage();
            doc.addPage(page);
            PDFont font1 = new PDType1Font(FontName.HELVETICA);
            PDFont font2 = PDType0Font.load(doc, PDFontTest.class.getResourceAsStream(
                    "/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"));

            assertEquals(font1.getStringWidth("-"), font1.getStringWidth("\u00AD"));
            assertEquals(font2.getStringWidth("-"), font2.getStringWidth("\u00AD"));

            try (PDPageContentStream cs = new PDPageContentStream(doc, page))
            {
                cs.beginText();
                cs.newLineAtOffset(100, 500);
                cs.setFont(font1, 10);
                cs.showText(text);
                cs.newLineAtOffset(0, 100);
                cs.setFont(font2, 10);
                cs.showText(text);
                cs.endText();
            }
            doc.save(baos);
        }
        
        try (PDDocument doc = Loader.loadPDF(baos.toByteArray()))
        {
            PDFTextStripper stripper = new PDFTextStripper();
            stripper.setLineSeparator("\n");
            String extractedText = stripper.getText(doc);
            assertEquals(text + "\n" + text, extractedText.trim());
        }
    }