Skip to content

Commit d4d24d9

Browse files
committed
fixes following comments
1 parent 08585d6 commit d4d24d9

4 files changed

Lines changed: 28 additions & 37 deletions

File tree

src/main/java/com/mindee/image/ImageExtractor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.mindee.geometry.PositionDataField;
55
import com.mindee.input.InputSourceUtils;
66
import com.mindee.input.LocalInputSource;
7-
import com.mindee.pdf.PdfPageImage;
7+
import com.mindee.pdf.PDFPageImage;
88
import java.awt.image.BufferedImage;
99
import java.io.ByteArrayInputStream;
1010
import java.io.IOException;
@@ -32,7 +32,7 @@ public ImageExtractor(LocalInputSource source) throws IOException {
3232
if (source.isPDF()) {
3333
this.saveFormat = "jpg";
3434
var pdfPageImages = pdfToImages(source.getFile(), this.filename);
35-
for (PdfPageImage pdfPageImage : pdfPageImages) {
35+
for (PDFPageImage pdfPageImage : pdfPageImages) {
3636
this.pageImages.add(pdfPageImage.getImage());
3737
}
3838
} else {
@@ -44,13 +44,13 @@ public ImageExtractor(LocalInputSource source) throws IOException {
4444
}
4545
}
4646

47-
public List<PdfPageImage> pdfToImages(byte[] fileBytes, String filename) throws IOException {
47+
public List<PDFPageImage> pdfToImages(byte[] fileBytes, String filename) throws IOException {
4848
PDDocument document = Loader.loadPDF(fileBytes);
4949
var pdfRenderer = new PDFRenderer(document);
50-
List<PdfPageImage> pdfPageImages = new ArrayList<>();
50+
List<PDFPageImage> pdfPageImages = new ArrayList<>();
5151
for (int i = 0; i < document.getNumberOfPages(); i++) {
5252
var imageBuffer = pdfPageToImageBuffer(i, document, pdfRenderer);
53-
pdfPageImages.add(new PdfPageImage(imageBuffer, i, filename, "jpg"));
53+
pdfPageImages.add(new PDFPageImage(imageBuffer, i, filename, "jpg"));
5454
}
5555
document.close();
5656
return pdfPageImages;

src/main/java/com/mindee/input/LocalInputSource.java

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public LocalInputSource(String fileAsBase64, String filename) {
6262
this.filename = filename;
6363
}
6464

65-
private PDFInputOperation getPdfInputOperator() {
65+
private PDFInputOperation getPDFInputOperator() {
6666
if (this.pdfInputOperator == null) {
6767
this.pdfInputOperator = new PDFInputOperator();
6868
}
6969
return this.pdfInputOperator;
7070
}
7171

72-
private PDFCompression getPdfCompressor() {
72+
private PDFCompression getPDFCompressor() {
7373
if (this.pdfCompressor == null) {
7474
this.pdfCompressor = new PDFCompressor();
7575
}
@@ -86,7 +86,7 @@ public int getPageCount() throws IOException {
8686
if (!this.isPDF()) {
8787
return 1;
8888
}
89-
return getPdfInputOperator().getPageCount(this.file);
89+
return getPDFInputOperator().getPageCount(this.file);
9090
}
9191

9292
/**
@@ -97,7 +97,7 @@ public int getPageCount() throws IOException {
9797
*/
9898
public void applyPageOptions(PageOptions pageOptions) throws IOException {
9999
if (pageOptions != null && this.isPDF()) {
100-
this.file = getPdfInputOperator().split(this.file, pageOptions).getFile();
100+
this.file = getPDFInputOperator().split(this.file, pageOptions).getFile();
101101
}
102102
}
103103

@@ -106,61 +106,52 @@ public void applyPageOptions(PageOptions pageOptions) throws IOException {
106106
*/
107107
public boolean isPDF() {
108108
if (this.isPDF == null) {
109-
this.isPDF = getPdfInputOperator().isPDF(this.file);
109+
this.isPDF = getPDFInputOperator().isPDF(this.file);
110110
}
111111
return this.isPDF;
112112
}
113113

114-
public LocalInputSource compress(
115-
Integer quality,
114+
public void compress(
115+
int quality,
116116
Integer maxWidth,
117117
Integer maxHeight,
118118
Boolean forceSourceText,
119119
Boolean disableSourceText
120120
) throws IOException {
121121
if (isPDF()) {
122-
this.file = getPdfCompressor()
122+
this.file = getPDFCompressor()
123123
.compressPDF(this.file, quality, forceSourceText, disableSourceText);
124124
} else {
125125
this.file = ImageCompressor.compressImage(this.file, quality, maxWidth, maxHeight);
126126
}
127-
return this;
128127
}
129128

130-
public LocalInputSource compress(
131-
Integer quality,
129+
public void compress(
130+
int quality,
132131
Integer maxWidth,
133132
Integer maxHeight,
134133
Boolean forceSourceText
135134
) throws IOException {
136-
return this.compress(quality, maxWidth, maxHeight, forceSourceText, true);
135+
this.compress(quality, maxWidth, maxHeight, forceSourceText, true);
137136
}
138137

139-
public LocalInputSource compress(
138+
public void compress(
140139
int quality,
141140
boolean forceSourceText,
142141
boolean disableSourceText
143142
) throws IOException {
144-
return this.compress(quality, null, null, forceSourceText, disableSourceText);
145-
}
146-
147-
public LocalInputSource compress(
148-
Integer quality,
149-
Integer maxWidth,
150-
Integer maxHeight
151-
) throws IOException {
152-
return this.compress(quality, maxWidth, maxHeight, false, true);
143+
this.compress(quality, null, null, forceSourceText, disableSourceText);
153144
}
154145

155-
public LocalInputSource compress(Integer quality, Integer maxWidth) throws IOException {
156-
return this.compress(quality, maxWidth, null, false, true);
146+
public void compress(int quality, Integer maxWidth, Integer maxHeight) throws IOException {
147+
this.compress(quality, maxWidth, maxHeight, false, true);
157148
}
158149

159-
public LocalInputSource compress(Integer quality) throws IOException {
160-
return this.compress(quality, null, null, false, true);
150+
public void compress(int quality) throws IOException {
151+
this.compress(quality, null, null, false, true);
161152
}
162153

163-
public LocalInputSource compress() throws IOException {
164-
return this.compress(85, null, null, false, true);
154+
public void compress() throws IOException {
155+
this.compress(85, null, null, false, true);
165156
}
166157
}

src/main/java/com/mindee/pdf/PdfPageImage.java renamed to src/main/java/com/mindee/pdf/PDFPageImage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
* A page in a PDF extracted as an image.
1717
*/
1818
@Getter
19-
public class PdfPageImage {
19+
public class PDFPageImage {
2020
private final BufferedImage image;
2121
private final int originalIndex;
2222
private final String saveFormat;
2323
private final String originalFilename;
2424

25-
public PdfPageImage(
25+
public PDFPageImage(
2626
BufferedImage image,
2727
int originalIndex,
2828
String originalFilename,

src/test/java/com/mindee/input/FileCompressionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ public void testPdfResizeWithTextKeepsText() throws IOException {
326326

327327
var originalDoc = Loader.loadPDF(initialWithText.getFile());
328328

329-
var compressedWithText = initialWithText.compress(100, true, false).getFile();
330-
var compressedDoc = Loader.loadPDF(compressedWithText);
329+
initialWithText.compress(100, true, false);
330+
var compressedDoc = Loader.loadPDF(initialWithText.getFile());
331331

332332
Assertions.assertEquals(originalDoc.getNumberOfPages(), compressedDoc.getNumberOfPages());
333333
Assertions.assertNotEquals(originalDoc.hashCode(), compressedDoc.hashCode());

0 commit comments

Comments
 (0)