title: Exporting specific string from pdf file using PDFbox
body: <p>I use this code for extracting the text of pdf file and saving into a txt file:</p>
  
  <pre><code>import java.io.*;
  import org.apache.pdfbox.pdmodel.*;
  import org.apache.pdfbox.util.*;
  
  public class PDFtest {
  
   public static void main(String[] args){
   PDDocument pd;
   BufferedWriter wr;
  
   try {
           File input = new File("C:\\Users\\User\\Downloads\\1212.pdf");
           File output = new File("C:\\Users\\User\\Downloads\\parse.txt"); 
           pd = PDDocument.load(input);
           System.out.println(pd.getNumberOfPages());
           System.out.println(pd.isEncrypted());
           PDFTextStripper stripper = new PDFTextStripper();
           stripper.setStartPage( 1 );
           stripper.setEndPage( 4 );
           wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)));
           stripper.writeText(pd, wr);
           if (pd != null) {
               pd.close();
           }
  
          wr.close();
   } catch (Exception e){
           e.printStackTrace();
          } 
       }
  }
  </code></pre>
  
  <p>I want to extract a specific string from the pdf file. For example the pdf file contains the following text:</p>
  
  <blockquote>
    <p>Unicode Converter enables you to easily convert Unicode characters to
    their Unicode and decimal representations. </p>
    
    <p>As you type in one of the text boxes below, the other boxes are
    converted on the fly.</p>
    
    <p>The Unicode converter doesn't automatically add spaces between the
    converted values. You can use the add spaces button to separate the
    Unicode characters so that the converted values will also be separated
    from one another.</p>
    
    <p>Whitespace characters are not converted unless the whitespace checkbox
    is checked.</p>
  </blockquote>
  
  <p>Let's say i want to extract the strings: </p>
  
  <blockquote>
    <p>Unicode Converter enables you to easily convert Unicode characters to
    their Unicode and decimal representations.</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>The Unicode converter doesn't automatically add spaces between the
    converted values. You can use the add spaces button to separate the
    Unicode characters so that the converted values will also be separated
    from one another.</p>
  </blockquote>
  
  <p>Can anyone give any help on this?</p>