|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -# Copyright (c) 2022-2024 Salvador E. Tropea |
3 | | -# Copyright (c) 2022-2024 Instituto Nacional de Tecnología Industrial |
| 2 | +# Copyright (c) 2022-2026 Salvador E. Tropea |
| 3 | +# Copyright (c) 2022-2026 Instituto Nacional de Tecnología Industrial |
4 | 4 | # License: AGPL-3.0 |
5 | 5 | # Project: KiBot (formerly KiPlot) |
6 | 6 | """ |
|
20 | 20 | import re |
21 | 21 | import pcbnew |
22 | 22 |
|
| 23 | +from .create_pdf import split_pdf |
23 | 24 | from .gs import GS |
24 | 25 | from .misc import (UI_SMD, UI_VIRTUAL, MOD_THROUGH_HOLE, MOD_SMD, MOD_EXCLUDE_FROM_POS_FILES, W_WRONGEXT, W_UNKPADSH, |
25 | 26 | W_WRONGOAR, W_ECCLASST, W_BLINDVIAS, W_MICROVIAS, W_BURIEDVIAS) |
@@ -238,6 +239,10 @@ def __init__(self): |
238 | 239 | self.csv_remove_leading_spaces = False |
239 | 240 | """ Remove any leading spaces/tabs at the end of each separator. |
240 | 241 | Used por templates that generates CSV files where elements are aligned for easier reading """ |
| 242 | + self.remove_split_pdfs = 'auto' |
| 243 | + """ [auto,yes,no] When we use PDF files they are split because `pandoc` can't deal with more than |
| 244 | + one page. You can delete them after converting the output. The `auto` value will do it when |
| 245 | + `do_convert` is enabled """ |
241 | 246 | super().__init__() |
242 | 247 | self._expand_id = 'report' |
243 | 248 | self._expand_ext = 'txt' |
@@ -1137,7 +1142,7 @@ def expand_converted_output(self, out_dir): |
1137 | 1142 | def get_targets(self, out_dir): |
1138 | 1143 | files = [self._parent.expand_filename(out_dir, self.output)] |
1139 | 1144 | if self.do_convert: |
1140 | | - files.append(self.expand_converted_output(out_dir)) |
| 1145 | + files.insert(0, self.expand_converted_output(out_dir)) |
1141 | 1146 | return files |
1142 | 1147 |
|
1143 | 1148 | def convert(self, fname): |
@@ -1183,6 +1188,7 @@ def run(self, fname): |
1183 | 1188 | self._layer_svgs = [] |
1184 | 1189 | self._schematic_pdfs = [] |
1185 | 1190 | self._schematic_svgs = [] |
| 1191 | + split_pdfs = [] |
1186 | 1192 | for o in RegOutput.get_outputs(): |
1187 | 1193 | dest = None |
1188 | 1194 | if o.type == 'pdf_pcb_print' or o.type == 'pcb_print': |
@@ -1210,13 +1216,24 @@ def run(self, fname): |
1210 | 1216 | comment = o.comment |
1211 | 1217 | if is_pcb_print_svg and o.options.pages[n].sheet: |
1212 | 1218 | comment += ' '+o.options.pages[n].sheet |
| 1219 | + # Split PDFs, otherwise we get the first page |
| 1220 | + if of.endswith('.pdf'): |
| 1221 | + split = split_pdf(of) |
| 1222 | + split_pdfs.extend(split) |
| 1223 | + if len(split) > 1: |
| 1224 | + for pdf_page, pdf_name in enumerate(split): |
| 1225 | + dest.append((os.path.relpath(pdf_name, base_dir), comment+f" page {pdf_page+1}", o.name)) |
| 1226 | + continue |
1213 | 1227 | dest.append((rel_path, comment, o.name)) |
1214 | 1228 | self.layer_pdfs = len(self._layer_pdfs) > 0 |
1215 | 1229 | self.layer_svgs = len(self._layer_svgs) > 0 |
1216 | 1230 | self.schematic_pdfs = len(self._schematic_pdfs) > 0 |
1217 | 1231 | self.schematic_svgs = len(self._schematic_svgs) > 0 |
1218 | 1232 | self.do_template(self.template, fname) |
1219 | 1233 | self.convert(fname) |
| 1234 | + if self.remove_split_pdfs == 'yes' or (self.remove_split_pdfs == 'auto' and self.do_convert): |
| 1235 | + for pdf_name in split_pdfs: |
| 1236 | + os.remove(pdf_name) |
1220 | 1237 |
|
1221 | 1238 |
|
1222 | 1239 | @output_class |
|
0 commit comments