Skip to content

Commit 1f1e88c

Browse files
committed
fixing bug that would cause 1-page extractions to break
1 parent 9b62c86 commit 1f1e88c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/java/com/jeffrpowell/pdfsplicer/BookletSplicer.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ protected Path doInBackground() throws Exception {
2626
}
2727
//Split pdfs
2828
try (PDDocument document = PDDocument.load(Files.readAllBytes(pathToSplit))) {
29-
if (document.isEncrypted()) {
30-
throw new UnsupportedOperationException("Error: Encrypted documents are not supported!");
31-
}
29+
document.setAllSecurityToBeRemoved(true);
3230
int j = 0;
3331
int noOfPages = document.getNumberOfPages();
3432
for (int i = 0; i < noOfPages; i++) {

src/main/java/com/jeffrpowell/pdfsplicer/Extractor.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.nio.file.Files;
44
import java.nio.file.Path;
5-
import java.nio.file.Paths;
65
import javax.swing.SwingWorker;
76
import org.apache.pdfbox.pdmodel.PDDocument;
87

@@ -15,7 +14,6 @@ public class Extractor extends SwingWorker<Path, Void>{
1514
private final int endPage;
1615

1716
public static int getPages(Path pdf) {
18-
int _pages = -1;
1917
try (PDDocument document = PDDocument.load(Files.readAllBytes(pdf))) {
2018
return document.getNumberOfPages();
2119
}
@@ -44,6 +42,13 @@ public Extractor(Path pathToSplit, int startPage, int endPage)
4442
protected Path doInBackground() throws Exception
4543
{
4644
try (PDDocument document = PDDocument.load(Files.readAllBytes(pathToSplit))) {
45+
document.setAllSecurityToBeRemoved(true);
46+
if (startPage == endPage) {
47+
try (PDDocument newDoc = new PDDocument()) {
48+
newDoc.addPage(document.getPage(startPage));
49+
newDoc.save(savePath.toFile());
50+
}
51+
}
4752
for (int page = pages - 1; page >= 0; page--) {
4853
if (page > endPage || page < startPage) {
4954
document.removePage(page);

0 commit comments

Comments
 (0)