Save the current document to file(s) >>> import os >>> from pagebot.toolbox.units import pt >>> from pagebot.filepaths import getRootPath >>> from pagebot.toolbox.color import blackColor >>> # _export/* Files are ignored in git. >>> exportPath = getRo
(self, path, multiPage=None)
| 197 | self._drawing.addpage() |
| 198 | |
| 199 | def saveDrawing(self, path, multiPage=None): |
| 200 | """Save the current document to file(s) |
| 201 | |
| 202 | >>> import os |
| 203 | >>> from pagebot.toolbox.units import pt |
| 204 | >>> from pagebot.filepaths import getRootPath |
| 205 | >>> from pagebot.toolbox.color import blackColor |
| 206 | >>> # _export/* Files are ignored in git. |
| 207 | >>> exportPath = getRootPath() + '/_export' |
| 208 | >>> if not exists(exportPath): os.makedirs(exportPath) |
| 209 | >>> context = FlatContext() |
| 210 | >>> w = h = pt(100) |
| 211 | >>> x = y = pt(0) |
| 212 | >>> c = blackColor |
| 213 | """ |
| 214 | |
| 215 | """ |
| 216 | FIX |
| 217 | >>> context.fileType = FILETYPE_JPG |
| 218 | >>> context.newPage(w, h) |
| 219 | >>> context.fill(c) |
| 220 | >>> context.rect(x, y, w-20, h-20) |
| 221 | # Flat is too strict with color-format match? |
| 222 | >>> context.saveDrawing(exportPath + '/MyTextDocument_F.%s' % FILETYPE_JPG) |
| 223 | >>> context.fileType = FILETYPE_PDF |
| 224 | >>> context.newPage(w, h) |
| 225 | >>> context.fill(c) |
| 226 | >>> context.rect(x, y, w-20, h-20) |
| 227 | # Flat is too strict with color-format match? |
| 228 | >>> context.saveDrawing(exportPath + '/MyTextDocument_F.%s' % FILETYPE_PDF) |
| 229 | >>> context.fileType = FILETYPE_PNG |
| 230 | >>> context.newPage(w, h) |
| 231 | >>> context.fill(c) |
| 232 | >>> context.rect(x, y, w-20, h-20) |
| 233 | >>> context.saveDrawing(exportPath + '/MyTextDocument_F.%s' % FILETYPE_PNG) |
| 234 | >>> context.saveDrawing(exportPath + '/MyTextDocument_F.gif') |
| 235 | [FlatContext] Gif not yet implemented for "MyTextDocument_F.gif" |
| 236 | """ |
| 237 | if not multiPage: |
| 238 | multiPage = True |
| 239 | # In case path starts with "_export", make sure that the directory |
| 240 | # exists. |
| 241 | self.checkExportPath(path) |
| 242 | self.fileType = path.split('.')[-1].lower() |
| 243 | |
| 244 | if self.fileType == FILETYPE_PNG: |
| 245 | if len(self._drawing.pages) == 1 or not multiPage: |
| 246 | im = self._drawing.pages[0].image(kind=RGB) |
| 247 | im.png(path) |
| 248 | else: |
| 249 | for n, p in enumerate(self._drawing.pages): |
| 250 | pagePath = path.replace('.'+FILETYPE_PNG, '%03d.%s' % (n, FILETYPE_PNG)) |
| 251 | p.image(kind=RGB).png(pagePath) |
| 252 | elif self.fileType == FILETYPE_JPG: |
| 253 | if len(self._drawing.pages) == 1 or not multiPage: |
| 254 | self._drawing.pages[0].image(kind=RGB).jpeg(path) |
| 255 | else: |
| 256 | for n, p in enumerate(self._drawing.pages): |
nothing calls this directly
no test coverage detected