public PDDocument extract() throws IOException
    {
        if (endPage - startPage + 1 <= 0)
        {
            return new PDDocument();
        }
        Splitter splitter = new Splitter();
        splitter.setStartPage(Math.max(startPage, 1));
        splitter.setEndPage(Math.min(endPage, sourceDocument.getNumberOfPages()));
        splitter.setSplitAtPage(getEndPage() - getStartPage() + 1);
        List<PDDocument> splitted = splitter.split(sourceDocument);
        return splitted.get(0);
    }
@Test
    void testExtract() throws Exception
    {
        PDDocument sourcePdf = null;
        PDDocument result = null;
        try
        {
            // this should work for most users
            sourcePdf = Loader.loadPDF(new File("src/test/resources/input/cweb.pdf"));
            PageExtractor instance = new PageExtractor(sourcePdf);
            result = instance.extract();
            assertEquals(sourcePdf.getNumberOfPages(), result.getNumberOfPages());
            closeDoc(result);
            
            instance = new PageExtractor(sourcePdf, 1, 1);
            result = instance.extract();
            assertEquals(1, result.getNumberOfPages());
            closeDoc(result);
            
            instance = new PageExtractor(sourcePdf, 1, 5);
            result = instance.extract();
            assertEquals(5, result.getNumberOfPages());
            closeDoc(result);
            
            instance = new PageExtractor(sourcePdf, 5, 10);
            result = instance.extract();
            assertEquals(6, result.getNumberOfPages());
            closeDoc(result);
            
            instance = new PageExtractor(sourcePdf, 2, 1);
            result = instance.extract();
            assertEquals(0, result.getNumberOfPages());
            closeDoc(result);
        }
        finally
        {
            closeDoc(sourcePdf);
            closeDoc(result);
        }
    }