Index: branches/vitalif/extensions/PdfHandler/PdfHandler_body.php |
— | — | @@ -93,7 +93,10 @@ |
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | if ( strpos( $page, '-' ) !== false ) { |
97 | | - $page = '$N'; |
| 97 | + list( $page, $endpage ) = explode( '-', $page, 2 ); |
| 98 | + if( !$page ) { |
| 99 | + $page = 1; |
| 100 | + } |
98 | 101 | } |
99 | 102 | return "page{$page}-{$params['width']}px"; |
100 | 103 | } |
— | — | @@ -101,7 +104,7 @@ |
102 | 105 | function parseParamString( $str ) { |
103 | 106 | $m = false; |
104 | 107 | |
105 | | - if ( preg_match( '/^page(\d+|\$N)-(\d+)px$/', $str, $m ) ) { |
| 108 | + if ( preg_match( '/^page(\d+)-(\d+)px$/', $str, $m ) ) { |
106 | 109 | return array( 'width' => $m[2], 'page' => $m[1] ); |
107 | 110 | } |
108 | 111 | |
— | — | @@ -147,7 +150,8 @@ |
148 | 151 | if ( $endpage === '' ) { |
149 | 152 | $endpage = $n; |
150 | 153 | } |
151 | | - $dstUrl = str_replace( 'page%24N', 'page$N', $dstUrl ); |
| 154 | + $dstPath = preg_replace( '/page\d+-/', 'page$N-', $dstPath ); |
| 155 | + $dstUrl = preg_replace( '/page\d+-/', 'page$N-', $dstUrl ); |
152 | 156 | } else { |
153 | 157 | $endpage = $page; |
154 | 158 | } |
— | — | @@ -178,7 +182,9 @@ |
179 | 183 | |
180 | 184 | // GhostScript fails (sometimes even crashes) if output filename length is > 255 bytes. |
181 | 185 | // Sometimes even when it's shorter. Workaround it by generating files in temporary directory. |
| 186 | + // Also, filenames include the sequence number of generated image, not the page number. |
182 | 187 | $dst = tempnam( wfTempDir(), 'pdf-' ); |
| 188 | + unlink( $dst ); |
183 | 189 | if ( $endpage > $page ) { |
184 | 190 | $dst .= '%d'; |
185 | 191 | } |
— | — | @@ -196,7 +202,7 @@ |
197 | 203 | // Move files from temporary directory to the destination |
198 | 204 | $removed = false; |
199 | 205 | for ( $i = $page; $i <= $endpage; $i++ ) { |
200 | | - $tmp = sprintf( $dst, $i ); |
| 206 | + $tmp = sprintf( $dst, $i-$page+1 ); |
201 | 207 | $real = str_replace( '$N', $i, $dstPath ); |
202 | 208 | if ( file_exists( $tmp ) ) { |
203 | 209 | rename( $tmp, $real ); |