Writing to Text file with PDFStripperByArea
<p>I'm trying to write the content of the PDF file being read into a text file. Help and advice would be greatly appreciated. Below is my lines of code so far. Thanks</p>

<pre><code>    try{
        String inputPath = "...";

        PDDocument pd = PDDocument.load(inputPath);

        PDFTextStripperByArea stripper = new PDFTextStripperByArea();

        stripper.setSortByPosition(true);

        while (pd!=null){


            Rectangle rect = new Rectangle(x,y,width,height);
            y++;

            stripper.addRegion("class1", rect);

            List allPages = pd.getDocumentCatalog().getAllPages();

            PDPage firstPage = (PDPage)allPages.get(0);

            stripper.extractRegions(firstPage);

            stripper.getTextForRegion("class1");
            stripper.toString();

            File outputDes = new File("RegionTest.txt");
            BufferedWriter wr = new BufferedWriter (new OutputStreamWriter(new FileOutputStream(outputDes)));
            stripper.writeText(pd, wr);
            //System.out.println("Text in the area:" + rect);
            System.out.println(stripper.getTextForRegion("class1"));
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
</code></pre>
