Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Java
Raw Normal View History

2023-09-09 00:25:27 +01:00
package stirling.software.SPDF.model.api;
import java.io.IOException;
import java.util.List;
2024-01-12 23:15:27 +00:00
import org.apache.pdfbox.Loader;
2023-09-09 00:25:27 +01:00
import org.apache.pdfbox.pdmodel.PDDocument;
2023-09-10 09:24:20 +01:00
2023-12-23 12:29:32 +00:00
import io.swagger.v3.oas.annotations.Hidden;
2023-09-09 00:25:27 +01:00
import io.swagger.v3.oas.annotations.media.Schema;
2023-12-30 19:11:27 +00:00
2023-09-09 00:25:27 +01:00
import lombok.Data;
2023-09-10 09:24:20 +01:00
import lombok.EqualsAndHashCode;
2023-09-09 00:25:27 +01:00
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
2023-09-09 00:25:27 +01:00
import stirling.software.SPDF.utils.GeneralUtils;
2023-12-30 19:11:27 +00:00
2023-09-09 00:25:27 +01:00
@Data
@NoArgsConstructor
@Slf4j
2023-09-10 09:24:20 +01:00
@EqualsAndHashCode(callSuper = true)
2023-09-09 00:25:27 +01:00
public class PDFWithPageNums extends PDFFile {
2023-12-30 19:11:27 +00:00
2023-09-09 00:25:27 +01:00
@Schema(
description =
"The pages to select, Supports ranges (e.g., '1,3,5-9'), or 'all' or functions in the"
+ " format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a"
+ " constant (e.g., '2n+1', '3n', '6n-5')\"")
2023-09-09 00:25:27 +01:00
private String pageNumbers;
2023-12-30 19:11:27 +00:00
2023-12-23 12:29:32 +00:00
@Hidden
2024-02-10 14:52:27 +00:00
public List<Integer> getPageNumbersList(boolean zeroCount) {
2023-09-09 00:25:27 +01:00
int pageCount = 0;
try {
2024-01-12 23:15:27 +00:00
pageCount = Loader.loadPDF(getFileInput().getBytes()).getNumberOfPages();
2023-09-09 00:25:27 +01:00
} catch (IOException e) {
// TODO Auto-generated catch block
log.error("exception", e);
2023-09-09 00:25:27 +01:00
}
return GeneralUtils.parsePageList(pageNumbers, pageCount, zeroCount);
2023-09-09 00:25:27 +01:00
}
2024-02-10 14:52:59 +00:00
2023-12-23 12:29:32 +00:00
@Hidden
2024-02-10 14:52:59 +00:00
public List<Integer> getPageNumbersList(PDDocument doc, boolean zeroCount) {
2023-09-09 00:25:27 +01:00
int pageCount = 0;
pageCount = doc.getNumberOfPages();
return GeneralUtils.parsePageList(pageNumbers, pageCount, zeroCount);
2023-09-09 00:25:27 +01:00
}
}