Java 阅读不带页眉和页脚的pdf,仅在、?之后插入新行,?![爪哇]

Java 阅读不带页眉和页脚的pdf,仅在、?之后插入新行,?![爪哇],java,pdf,newline,header-files,pdfbox,Java,Pdf,Newline,Header Files,Pdfbox,我有很多pdf文件(不同格式的文章)。我想阅读内容并将其写入一个.txt文件,但忽略页眉和页脚,并且我只想在以下符号之后有一行新行: 可能吗? 我使用了PDFBox,我已经删除了句子中间的新行,但我不知道在一个句子的结尾添加新行。在我阅读的文本中还有页眉和页脚 我的实际代码: PDDocument pd; BufferedWriter wr; String outputFilename = filename.split(".pdf")[0] + ".txt"; t

我有很多pdf文件(不同格式的文章)。我想阅读内容并将其写入一个.txt文件,但忽略页眉和页脚,并且我只想在以下符号之后有一行新行:

可能吗? 我使用了PDFBox,我已经删除了句子中间的新行,但我不知道在一个句子的结尾添加新行。在我阅读的文本中还有页眉和页脚

我的实际代码:

    PDDocument pd;
    BufferedWriter wr;
    String outputFilename = filename.split(".pdf")[0] + ".txt";
    try {
        File input = new File(filename);  // The PDF file from where you would like to extract
        File output = new File(outputFilename); // The text file where you are going to store the extracted data
        pd = PDDocument.load(input);
        System.out.println("Output filename:" + output.getName());
        System.out.println("Number of pages:" + pd.getNumberOfPages());
        System.out.println("Encrypted:" + pd.isEncrypted());
        PDFTextStripper stripper = new PDFTextStripper()
        {
            @Override
            protected void processTextPosition(TextPosition text)
            {
                String character = text.getCharacter();
                if (character != null && character.trim().length() != 0)
                    super.processTextPosition(text);
            }
        };
        stripper.setSortByPosition(true);
        stripper.setLineSeparator("");
        wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)));
        wr.write(stripper.getText(pd));
        //stripper.writeText(pd, wr);
        if (pd != null) {
            pd.close();
        }
        wr.close();
    } catch (Exception e){
        e.printStackTrace();
    }
此外,我对具有两列格式的文档也有问题,如:。当我提取文本时,我得到一个文本文件,其中的列被合并为结果(即,来自同一行中两列的文本)


谢谢

软件可以根据哪些标准识别PDF中的页眉和页脚?它们有标签吗?没有特定的图案。例如,我有一个这样的pdf。这些文件来自不同的域,因此没有定义的单词模式。标题确实没有什么特别之处。因此,如果要忽略页眉和页脚,则必须为此提供外部条件。