How to extract font styles of text contents using pdfbox?

前端 未结 3 667
青春惊慌失措
青春惊慌失措 2020-12-10 18:03

I am using pdfbox library to extract text contents from pdf file.I would able to extract all the text,but couldn\'t find the method to extract font styles.

3条回答
  •  离开以前
    2020-12-10 18:44

    File file = new File("sample.pdf");
            PDDocument document = PDDocument.load(file);
    
            for (int i = 0; i < document.getNumberOfPages(); ++i)
            {
                PDPage page = document.getPage(i);
                PDResources res = page.getResources();
                for (COSName fontName : res.getFontNames())
                {
                    PDFont font = res.getFont(fontName);
                    System.out.println(font.getName());
    
                }
            }
    

提交回复
热议问题