Skip to content

Commit fec9748

Browse files
authored
Allowing number of pages to be converted on oversized PDFs to be configurable (#654)
1 parent 0b08a49 commit fec9748

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/java/formflow/library/file/FileConversionService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class FileConversionService {
5151
@Value("${form-flow.uploads.file-conversion.max-conversion-size:}")
5252
private Integer maxConversionSize;
5353

54+
@Value("${form-flow.uploads.file-conversion.max-pages:}")
55+
private Integer maxPages;
56+
5457
@Value("${form-flow.uploads.max-file-size}")
5558
Integer maxFileSize;
5659

@@ -313,6 +316,12 @@ private Set<MultipartFile> convertOfficeDocumentToPDF(MultipartFile file) {
313316

314317
reader = new PdfReader(compressedPDFFile.getAbsolutePath());
315318
int totalPages = reader.getNumberOfPages();
319+
320+
if (maxPages != null && totalPages > maxPages) {
321+
log.warn("Too many pages found for PDF conversion. Only converting {} of {} pages.", maxPages, totalPages);
322+
totalPages = maxPages;
323+
}
324+
316325
if (totalPages > 1) {
317326
for (int i = 1; i <= totalPages; i++) {
318327
String outputFilePath = compressedPDFFile.getAbsolutePath() + "_page_" + i + ".pdf";

0 commit comments

Comments
 (0)