Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping last page #35

Open
jacobmyers-codeninja opened this issue Apr 19, 2018 · 1 comment
Open

Skipping last page #35

jacobmyers-codeninja opened this issue Apr 19, 2018 · 1 comment

Comments

@jacobmyers-codeninja
Copy link

jacobmyers-codeninja commented Apr 19, 2018

After processing a bunch of pdf files I noticed that the last page always seems to be skipped and not included in the output. I looked through the code some and I believe the error is due to a logic mistake in the hasNext() of extraction/JPedalExtractor.java

@Override
public boolean hasNext() {

	boolean haveNext = false;

	while (currentPage <= pageCount && !haveNext) {

		try {

			haveNext = decodeFile();

		} catch (EmptyPDFException e) {

			break;

		} catch (Exception e) {

			e.printStackTrace();
			break;

		}

	}

	if (currentPage == pageCount + 1) {

		pdfDecoder.flushObjectValues(true);
		pdfDecoder.closePdfFile();
		haveNext = false;

	}

	return haveNext;

}

The issue seems to be caused by the line haveNext = false; in the final if statement. When the last page is reached it always returns false for hasNext as a result of this, even if there is still a page to process. Commenting out this line seems to allow it to generate the final page output without any issues, but I don't know if this is the best/correct thing to do.

This was all done with what should be the version published in github as built with maven (version 1.7.7).

@rosenjcb
Copy link

I just spent 3 hours debugging this to see this issue in the tracker. Wow, thank goodness I'm not the only one having this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants