Draw the selected pages. pageSelection is an optional set of y-pageNumbers to draw. >>> from pagebot.document import Document >>> from pagebot.constants import BusinessCard, A4, QUIRE_QUARTO >>> doc = Document(size=A4, autoPages=4) # Make 4 pages to be composed as a
(self, path=None, pageSelection=None, multiPage=True, **kwargs)
| 42 | EXPORT_PATH = '_export/' # Default path for local document export, that does not commit documents to Github. |
| 43 | |
| 44 | def build(self, path=None, pageSelection=None, multiPage=True, **kwargs): |
| 45 | """Draw the selected pages. pageSelection is an optional set of |
| 46 | y-pageNumbers to draw. |
| 47 | |
| 48 | >>> from pagebot.document import Document |
| 49 | >>> from pagebot.constants import BusinessCard, A4, QUIRE_QUARTO |
| 50 | >>> doc = Document(size=A4, autoPages=4) # Make 4 pages to be composed as a Quire of 2 spreads |
| 51 | >>> view = doc.view |
| 52 | >>> q1 = view.newQuire(folds=QUIRE_QUARTO) |
| 53 | >>> q2 = view.newQuire(folds=QUIRE_QUARTO) |
| 54 | >>> len(view.elements) |
| 55 | 2 |
| 56 | >>> len(view.elements[0]) |
| 57 | 8 |
| 58 | """ |
| 59 | if not path: |
| 60 | path = self.EXPORT_PATH + self.doc.name + '.pdf' # Default export as PDF. |
| 61 | |
| 62 | # If default _export directory does not exist, then create it. |
| 63 | if path.startswith(self.EXPORT_PATH) and not os.path.exists(self.EXPORT_PATH): |
| 64 | os.makedirs(self.EXPORT_PATH) |
| 65 | |
| 66 | # Save the intended extension into the context, so it knows what we'll |
| 67 | # be saving to. |
| 68 | self.context.fileType = path.split('.')[-1] |
| 69 | |
| 70 | # Find the maximum document page size to this in all page sizes of the |
| 71 | # document. |
| 72 | w, h, _ = self.doc.getMaxPageSizes(pageSelection) |
| 73 | |
| 74 | # Make sure that canvas is empty, there may have been another document |
| 75 | # building in this context. |
| 76 | self.context.newPage(w=w, h=h, doc=self.doc) |
| 77 | |
| 78 | for pn, pages in self.doc.getSortedPages(): |
| 79 | #if pageSelection is not None and not page.y in pageSelection: |
| 80 | # continue |
| 81 | |
| 82 | # Create a new DrawBot viewport page to draw template + page, if |
| 83 | # not already done. In case the document is oversized, then make |
| 84 | # all pages the size of the document, so the pages can draw their |
| 85 | # crop-marks. Otherwise make DrawBot pages of the size of each |
| 86 | # page. Size depends on the size of the larges pages + optional |
| 87 | # decument padding. |
| 88 | # TODO: make this work for pages that share the same page number. |
| 89 | page = pages[0] |
| 90 | # Copy from main (w, h), since they may be altered, from the |
| 91 | # orgiinal document size. |
| 92 | pw, ph = w, h |
| 93 | |
| 94 | if self.pl >= self.viewMinInfoPadding and \ |
| 95 | self.pt >= self.viewMinInfoPadding and \ |
| 96 | self.pb >= self.viewMinInfoPadding and \ |
| 97 | self.pr >= self.viewMinInfoPadding: |
| 98 | pw += self.pl + self.pr |
| 99 | ph += self.pt + self.pb |
| 100 | origin = self.pl, self.pb, pt(0) |
| 101 | else: |
no test coverage detected