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 >>> from pagebot.contexts import getContext >>> context = getContext
(self, path=None, pageSelection=None, multiPage=True, **kwargs)
| 83 | return sortedPages |
| 84 | |
| 85 | def build(self, path=None, pageSelection=None, multiPage=True, **kwargs): |
| 86 | """Draw the selected pages. pageSelection is an optional set of |
| 87 | y-pageNumbers to draw. |
| 88 | |
| 89 | >>> from pagebot.document import Document |
| 90 | >>> from pagebot.constants import BusinessCard, A4, QUIRE_QUARTO |
| 91 | >>> from pagebot.contexts import getContext |
| 92 | >>> context = getContext() |
| 93 | >>> # Make 4 pages to be composed as a Quire of 2 spreads. |
| 94 | >>> doc = Document(size=A4, autoPages=4, context=context) |
| 95 | >>> view = doc.view |
| 96 | >>> q = view.newQuire(folds=QUIRE_QUARTO) |
| 97 | >>> len(view.elements) |
| 98 | 1 |
| 99 | >>> len(view.elements[0]) |
| 100 | 8 |
| 101 | """ |
| 102 | if not path: |
| 103 | path = self.EXPORT_PATH + self.doc.name + '.pdf' # Default export as PDF. |
| 104 | |
| 105 | # If default _export directory does not exist, then create it. |
| 106 | if path.startswith(self.EXPORT_PATH) and not os.path.exists(self.EXPORT_PATH): |
| 107 | os.makedirs(self.EXPORT_PATH) |
| 108 | |
| 109 | # Save the intended extension into the context, so it knows what we'll |
| 110 | # be saving to. |
| 111 | context = self.context |
| 112 | assert context is not None |
| 113 | context.fileType = path.split('.')[-1] |
| 114 | |
| 115 | # Find the maximum document page size to this in all page sizes of the |
| 116 | # document. |
| 117 | w, h, _ = self.doc.getMaxPageSizes(pageSelection) |
| 118 | |
| 119 | # Make sure that canvas is empty, there may have been another document |
| 120 | # building in this context. Allow the context to create a new document |
| 121 | # and page canvas. |
| 122 | |
| 123 | if self.pl >= self.viewMinInfoPadding and \ |
| 124 | self.pt >= self.viewMinInfoPadding and \ |
| 125 | self.pb >= self.viewMinInfoPadding and \ |
| 126 | self.pr >= self.viewMinInfoPadding: |
| 127 | w += self.pl + self.pr |
| 128 | h += self.pt + self.pb |
| 129 | |
| 130 | self.context.newDrawing(w=w, h=h) |
| 131 | |
| 132 | # Get dictionary of pages or spreads |
| 133 | sortedPages = self.getSortedPages() |
| 134 | |
| 135 | # Recursively let all element prepare for the upcoming build, e.g. by |
| 136 | # saving scaled images in cache if they do not already exists. Note |
| 137 | # that this is executed on a page-by-page level, not all at once. |
| 138 | for pn, pages in sortedPages: |
| 139 | for page in pages: |
| 140 | page.prepare(self) |
| 141 | |
| 142 | for pn, pages in sortedPages: |
no test coverage detected