Example usage for org.apache.pdfbox.text PDFTextStripper setStartPage

List of usage examples for org.apache.pdfbox.text PDFTextStripper setStartPage

Introduction

In this page you can find the example usage for org.apache.pdfbox.text PDFTextStripper setStartPage.

Prototype

public void setStartPage(int startPageValue) 

Source Link

Document

This will set the first page to be extracted by this class.

Usage

From source file:src.controller.DocumentController.java

public void convertToDocX(File filepath, File filename) {

    PDDocument documentpdf;//from   www  .  ja va 2s  . com

    try {

        documentpdf = PDDocument.load(filepath);

        PDFTextStripper pdfStripper = new PDFTextStripper();
        pdfStripper.setStartPage(1);
        //pdfStripper.setEndPage( 1 );

        String parsedText = pdfStripper.getText(documentpdf);
        System.out.println(parsedText);

        // enregistrement du document dans un fichier
        FileOutputStream out = new FileOutputStream(filepath + filename.toString() + ".docx");

        XWPFDocument document = new XWPFDocument();

        //create Paragraph
        XWPFParagraph paragraph = document.createParagraph();
        XWPFRun run = paragraph.createRun();

        run.setText(parsedText);

        document.write(out);

        out.close();

    } catch (IOException ex) {
        Logger.getLogger(DocumentController.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:uk.org.openeyes.PDFFunctions.java

/**
 *
 * @param PDFDoc//from   ww  w .ja va  2s .co  m
 * @throws IOException
 */
public void dumpPDFStructure(PDDocument PDFDoc) throws IOException {
    PDFTextStripper stripper = new PDFFunctions();
    stripper.setSortByPosition(true);
    stripper.setStartPage(0);
    stripper.setEndPage(PDFDoc.getNumberOfPages());
    Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
    stripper.writeText(PDFDoc, dummy);

}