@@ -118,12 +118,6 @@ export class SplitPdfHook
118
118
119
119
let pagesCount = pageRangeEnd - pageRangeStart + 1 ;
120
120
121
- if ( pagesCount < MIN_PAGES_PER_THREAD ) {
122
- console . info (
123
- `PDF has less than ${ MIN_PAGES_PER_THREAD } pages. Partitioning without split.`
124
- ) ;
125
- return request ;
126
- }
127
121
128
122
const startingPageNumber = getStartingPageNumber ( formData ) ;
129
123
console . info ( "Starting page number set to %d" , startingPageNumber ) ;
@@ -137,14 +131,16 @@ export class SplitPdfHook
137
131
const splitSize = await getOptimalSplitSize ( pagesCount , concurrencyLevel ) ;
138
132
console . info ( "Determined optimal split size of %d pages." , splitSize )
139
133
140
- // If the doc is small enough, and we aren't slicing it with a page range:
141
- // do not split, just continue with the original request
142
- if ( splitSize >= pagesCount && pagesCount == totalPages ) {
143
- console . info (
134
+ // If we aren't requesting a slice of the pdf, i.e. the page range covers the total page count
135
+ // and if the doc is small enough, do not split, just continue with the original request
136
+ if ( pagesCount == totalPages ) {
137
+ if ( splitSize >= pagesCount || pagesCount < MIN_PAGES_PER_THREAD ) {
138
+ console . info (
144
139
"Document has too few pages (%d) to be split efficiently. Partitioning without split." ,
145
140
pagesCount ,
146
- )
147
- return request ;
141
+ )
142
+ return request ;
143
+ }
148
144
}
149
145
150
146
const splits = await splitPdf ( pdf , splitSize , pageRangeStart , pageRangeEnd ) ;
0 commit comments