def job_for_name(container, name, margins, page_layout): index_file = container.name_to_abspath(name) if margins: page_layout = QPageLayout(page_layout) page_layout.setUnits(QPageLayout.Unit.Point) new_margins = QMarginsF(*resolve_margins(margins, page_layout)) page_layout.setMargins(new_margins) return index_file, page_layout, name
def get_page_layout(opts, for_comic=False): page_size = get_page_size(opts, for_comic) def m(which): return max( 0, getattr(opts, 'pdf_page_margin_' + which) or getattr(opts, 'margin_' + which)) margins = QMarginsF(m('left'), m('top'), m('right'), m('bottom')) ans = QPageLayout(page_size, QPageLayout.Orientation.Portrait, margins) ans.setMode(QPageLayout.Mode.FullPageMode) return ans
def start_print(self, data): margins = QMarginsF(0, 0, 0, 0) page_size = QPageSize(QPageSize.PageSizeId.A4) if isinstance(data, dict): try: if 'margins' in data: margins = QMarginsF(*data['margins']) if 'size' in data: sz = data['size'] if type(getattr(QPageSize, sz, None)) is type( QPageSize.PageSizeId.A4): # noqa page_size = QPageSize(getattr(QPageSize, sz)) else: from calibre.ebooks.pdf.image_writer import parse_pdf_page_size ps = parse_pdf_page_size(sz, data.get('unit', 'inch')) if ps is not None: page_size = ps except Exception: pass page_layout = QPageLayout(page_size, QPageLayout.Orientation.Portrait, margins) self.printToPdf('rendered.pdf', page_layout) self.printing_started = True self.start_time = monotonic()
def do_print(self, ok): p = QPageLayout(QPageSize(QPageSize(QPageSize.PageSizeId.A4)), QPageLayout.Orientation.Portrait, QMarginsF(72, 0, 72, 0)) self.printToPdf(self.print_finished, p)