()
| 153 | |
| 154 | |
| 155 | def test_3789(): |
| 156 | |
| 157 | file_path = os.path.abspath(f'{__file__}/../../tests/resources/test_3789.pdf') |
| 158 | result_path = os.path.abspath(f'{__file__}/../../tests/test_3789_out') |
| 159 | pages_per_split = 5 |
| 160 | |
| 161 | # Clean pdf |
| 162 | doc = pymupdf.open(file_path) |
| 163 | tmp = io.BytesIO() |
| 164 | tmp.write(doc.write(garbage=4, deflate=True)) |
| 165 | |
| 166 | source_doc = pymupdf.Document('pdf', tmp.getvalue()) |
| 167 | tmp.close() |
| 168 | |
| 169 | # Calculate the number of pages per split file and the number of split files |
| 170 | page_range = pages_per_split - 1 |
| 171 | split_range = range(0, source_doc.page_count, pages_per_split) |
| 172 | num_splits = len(split_range) |
| 173 | |
| 174 | # Loop through each split range and create a new PDF file |
| 175 | for i, start in enumerate(split_range): |
| 176 | output_doc = pymupdf.open() |
| 177 | |
| 178 | # Determine the ending page for this split file |
| 179 | to_page = start + page_range if i < num_splits - 1 else -1 |
| 180 | output_doc.insert_pdf(source_doc, from_page=start, to_page=to_page) |
| 181 | |
| 182 | # Save the output document to a file and add the path to the list of split files |
| 183 | path = f'{result_path}_{i}.pdf' |
| 184 | output_doc.save(path, garbage=2) |
| 185 | print(f'Have saved to {path=}.') |
| 186 | |
| 187 | # If this is the last split file, exit the loop |
| 188 | if to_page == -1: |
| 189 | break |
| 190 | |
| 191 | |
| 192 | def test_widget_insert(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…