Python reportlab.lib.pagesizes.A4 Examples
The following are 18
code examples of reportlab.lib.pagesizes.A4().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
reportlab.lib.pagesizes
, or try the search function
.
Example #1
Source File: report.py From nanopype with MIT License | 7 votes |
def __init__(self, cwd, output, version=''): self.cwd = cwd self.tag = os.path.basename(os.path.normpath(self.cwd)) self.version = version self.story = [] stylesheet = getSampleStyleSheet() self.title_style = stylesheet['Title'] self.heading_style = stylesheet['Heading2'] self.heading2_style = stylesheet['Heading3'] self.normal_style = stylesheet['Normal'] self.body_style = stylesheet['BodyText'] self.current_section = 0 self.doc = doc = SimpleDocTemplate(output, pagesize=A4, leftMargin=2.2*cm, rightMargin=2.2*cm, topMargin=1.5*cm,bottomMargin=2.5*cm) self.plot_width = self.doc.width * 0.85 self.plot_scale = 0.4
Example #2
Source File: pdf.py From correios with Apache License 2.0 | 6 votes |
def __init__(self, page_size=pagesizes.A4, shipping_labels_margin=(0, 0), posting_list_margin=(5 * mm, 5 * mm)): self.shipping_labels = [] # type: List[ShippingLabel] self._tracking_codes = set() self.page_size = page_size self.page_width = page_size[0] self.page_height = page_size[1] self.posting_list = None # type: PostingList self.posting_list_margin = posting_list_margin self.shipping_labels_margin = shipping_labels_margin self.shipping_labels_width = self.page_width - (2 * shipping_labels_margin[0]) self.shipping_labels_height = self.page_height - (2 * shipping_labels_margin[1]) self.col_size = self.shipping_labels_width / 2 self.row_size = self.shipping_labels_height / 2 self._label_position = ( (shipping_labels_margin[0], self.page_height / 2), (shipping_labels_margin[0] + self.col_size, self.page_height / 2), (shipping_labels_margin[0], shipping_labels_margin[1]), (shipping_labels_margin[0] + self.col_size, shipping_labels_margin[1]), )
Example #3
Source File: barcodeMaker.py From HH---POS-Accounting-and-ERP-Software with MIT License | 6 votes |
def makeBarcodeFile (brc, width, height): brc = str(brc) width = float(width) * mm height = float(height) * mm # generate a canvas (A4 in this case, size doesn"t really matter) c=canvas.Canvas(brc+".pdf",pagesize=A4) # create a barcode object # (is not displayed yet) # The encode text is "123456789" # barHeight encodes how high the bars will be # barWidth encodes how wide the "narrowest" barcode unit is barcode=code39.Extended39(brc, barWidth=width*mm, barHeight=height*mm) # drawOn puts the barcode on the canvas at the specified coordinates x, y = (10*mm, 10*mm) while y + barcode.height < 290*mm: while x + barcode.width < 200*mm: barcode.drawOn(c, x, y) x = x + (1 + barcode.width) x = 10*mm y = y + (1 + barcode.height)*mm # now create the actual PDF c.showPage() c.save()
Example #4
Source File: privacy.py From deda with GNU General Public License v3.0 | 5 votes |
def apply(self, inPdf): """ @inPdf pdf binary, None for empty page """ if inPdf is None: return self._createMask() inPdf = self.pdfNormaliseFormat(inPdf,*self.pagesize) # force A4 if "wand" in globals(): return self.pdfWatermark(inPdf, self._createMask, True) else: self.maskpdf = self._createMask() return self.pdfWatermark(inPdf, lambda *args:self.maskpdf, False)
Example #5
Source File: pdfinvoice.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, page_size=A4, font_face='Helvetica'): self.page_size = page_size self.font_face = font_face self.logo = None
Example #6
Source File: pdf.py From pylinac with MIT License | 5 votes |
def __init__(self, filename: str, page_title: str, font: str="Helvetica", metadata: dict=None, metadata_location: tuple=(2, 25.5)): self.canvas = Canvas(filename, pagesize=A4) self._font = font self._title = page_title self._metadata = metadata self._metadata_location = metadata_location self._generate_pylinac_template_theme() self._add_metadata()
Example #7
Source File: lto.py From stdm with GNU General Public License v2.0 | 5 votes |
def test() : """Test this.""" from reportlab.pdfgen.canvas import Canvas from reportlab.lib import pagesizes canvas = Canvas("labels.pdf", pagesize=pagesizes.A4) canvas.setFont("Helvetica", 30) (width, height) = pagesizes.A4 canvas.drawCentredString(width/2.0, height-4*cm, "Sample LTO labels") xpos = xorig = 2 * cm ypos = yorig = 2 * cm colwidth = 10 * cm lineheight = 3.9 * cm count = 1234 BaseLTOLabel("RL", count, "3").drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 BaseLTOLabel("RL", count, "3", border=0.0125).drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3").drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3", border=0.0125).drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3", colored=True).drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3", border=0.0125, colored=True).drawOn(canvas, xpos, ypos) canvas.showPage() canvas.save()
Example #8
Source File: Screenshot_to_pdf.py From crawlBaiduWenku with MIT License | 5 votes |
def pic_to_pdf(page_count,wenku_title): filename=wenku_title+'\\'+wenku_title+'.pdf' c = canvas.Canvas(filename) (w,h) = portrait(A4) print('开始写入pdf') for i in range(1,page_count+1): c.drawImage('{}/第{}页图片.png'.format(wenku_title,i),0,0,w,h) c.showPage() c.save() print('文件保存在{}文件夹下的{}.pdf中'.format(wenku_title,wenku_title))
Example #9
Source File: pic_to_pdf.py From crawlBaiduWenku with MIT License | 5 votes |
def pic_to_pdf(filename): if '.pdf' not in filename: filename=filename+'.pdf' c = canvas.Canvas(filename) (w,h) = portrait(A4) for i in range(2): while True : try: c.drawImage(str(i+1)+'.png',0,0,w,h) c.showPage() break except: pass c.save() print('文件保存为{}.pdf'.format(filename))
Example #10
Source File: crawlBaiduWenku.py From crawlBaiduWenku with MIT License | 5 votes |
def pic_to_pdf(page_count,wenku_title): filename=wenku_title+'\\'+wenku_title+'.pdf' c = canvas.Canvas(filename) (w,h) = portrait(A4) print('开始写入pdf') for i in range(1,page_count+1): c.drawImage('{}/第{}页图片.png'.format(wenku_title,i),0,0,w,h) c.showPage() c.save() print('文件保存在{}文件夹下的{}.pdf中'.format(wenku_title,wenku_title))
Example #11
Source File: img2pdf.py From TencentComicBook with MIT License | 5 votes |
def imgs_to_pdf(img_path_list, target_path): """将一组图片合成一个pdf文件 :param str target_path: 输出pdf文件路径 :param list img_path_list: 要合成的图片的路径列表 :return str target_path: 输出pdf文件路径 """ a4_w, a4_h = portrait(A4) c = canvas.Canvas(target_path, pagesize=portrait(A4)) for img_path in img_path_list: img_w, img_h = ImageReader(img_path).getSize() if img_w / img_h > a4_w / a4_h: # 横图 ratio = a4_w / img_w left_margin = 0 top_margin = (a4_h - img_h * ratio) / 2 else: # 竖图 ratio = a4_h / img_h left_margin = (a4_w - img_w * ratio) / 2 top_margin = 0 c.drawImage(img_path, left_margin, top_margin, img_w * ratio, img_h * ratio) c.showPage() os.makedirs(os.path.dirname(target_path), exist_ok=True) c.save() return target_path
Example #12
Source File: datasheet.py From pychemqt with GNU General Public License v3.0 | 5 votes |
def __init__(self, titulo): self.c = canvas.Canvas("datasheet.pdf", pagesize=A4) self.c.setTitle(titulo)
Example #13
Source File: fd_api_doc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def write_pdf(self, mod): file_path = os.path.join(self.write_path if self.write_path != "" else mod.__path__[0], "doc") file_name = mod.__package__ + ".pdf" if not os.path.exists(file_path): os.mkdir(file_path) doc = SimpleDocTemplate(os.path.join(file_path, file_name), pagesize = A4, leftMargin = 0.25 * inch, rightMargin = 0.25 * inch, topMargin = 0.25 * inch, bottomMargin = 0.25 * inch) lib_name = mod.__package__.replace("_", " ") self.create_hdr(lib_name, font_size=24) print("\n", lib_name, "\n") dirs = self.read_include_file(os.path.join(mod.__path__[0], "doc")) if len(dirs) > 0: for d in dirs: path = os.path.join(mod.__path__[0], d) if os.path.exists(path): self.create_hdr(d.title(), font_size=18) self.search_dir(path) else: products_path = os.path.join(mod.__path__[0], "products") if os.path.exists(products_path): self.create_hdr("Products", font_size=18) self.search_dir(products_path) inserts_path = os.path.join(mod.__path__[0], "inserts") if os.path.exists(inserts_path): self.create_hdr("Inserts", font_size=18) self.search_dir(inserts_path) doc.build(self.elements)
Example #14
Source File: lto.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test() : """Test this.""" from reportlab.pdfgen.canvas import Canvas from reportlab.lib import pagesizes canvas = Canvas("labels.pdf", pagesize=pagesizes.A4) canvas.setFont("Helvetica", 30) (width, height) = pagesizes.A4 canvas.drawCentredString(width/2.0, height-4*cm, "Sample LTO labels") xpos = xorig = 2 * cm ypos = yorig = 2 * cm colwidth = 10 * cm lineheight = 3.9 * cm count = 1234 BaseLTOLabel("RL", count, "3").drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 BaseLTOLabel("RL", count, "3", border=0.0125).drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3").drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3", border=0.0125).drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3", colored=True).drawOn(canvas, xpos, ypos) ypos += lineheight count += 1 VerticalLTOLabel("RL", count, "3", border=0.0125, colored=True).drawOn(canvas, xpos, ypos) canvas.showPage() canvas.save()
Example #15
Source File: reporting.py From attack_monitor with GNU General Public License v3.0 | 5 votes |
def __init__(self, GATHERING_OPTIONS, CONTAINERS, PROCESS_TREE): self.report_date = nicedate.NiceDate.get_now() self.timezone = nicedate.CONFIG_TIMEZONE self.CONTAINERS = CONTAINERS self.GATHERING_OPTIONS = GATHERING_OPTIONS self.PROCESS_TREE = PROCESS_TREE self.report_filename = self.GATHERING_OPTIONS['report_dir'] + "\\" + "malware_report_" + self.report_date.strftime("%Y-%m-%d %H_%M_%S") + ".pdf" self.canvas = canvas.Canvas(self.report_filename, pagesize=A4) #PDF self.pdf_initalize_styles() self.f = [] self.doc = SimpleDocTemplate(self.report_filename)
Example #16
Source File: report.py From nanopype with MIT License | 5 votes |
def on_later_pages(self, canvas, doc): canvas.saveState() canvas.setFont('Helvetica', 10) canvas.setLineWidth(0.5) canvas.line(doc.leftMargin, 1.5*cm, A4[0]-doc.rightMargin, 1.5*cm) canvas.drawString(doc.leftMargin, 0.8*cm, "Nanopype report") canvas.drawCentredString(A4[0] // 2, 0.8 * cm, "{:d}".format(doc.page)) canvas.drawRightString(A4[0] - doc.rightMargin, 0.8*cm, "{}".format(self.tag)) canvas.restoreState()
Example #17
Source File: report.py From nanopype with MIT License | 5 votes |
def on_first_page(self, canvas, doc): canvas.saveState() canvas.rotate(90) canvas.setFont('Helvetica-Bold', 100) canvas.setFillGray(0.8) canvas.drawString(0, -0.95*A4[0], "Nanopype") canvas.restoreState()
Example #18
Source File: utils.py From asm3 with GNU General Public License v3.0 | 4 votes |
def html_to_pdf_pisa(dbo, htmldata): """ Converts HTML content to PDF and returns the PDF file data as bytes. NOTE: wkhtmltopdf is far superior, but this is a pure Python solution and it does work. """ # Allow orientation and papersize to be set # with directives in the document source - eg: <!-- pdf orientation landscape, pdf papersize letter --> orientation = "portrait" # Sort out page size arguments papersize = "A4" if htmldata.find("pdf orientation landscape") != -1: orientation = "landscape" if htmldata.find("pdf orientation portrait") != -1: orientation = "portrait" if htmldata.find("pdf papersize a5") != -1: papersize = "A5" if htmldata.find("pdf papersize a4") != -1: papersize = "A4" if htmldata.find("pdf papersize a3") != -1: papersize = "A3" if htmldata.find("pdf papersize letter") != -1: papersize = "letter" # Zoom - eg: <!-- pdf zoom 0.5 end --> # Not supported in any meaningful way by pisa (not smart scaling) # zm = regex_one("pdf zoom (.+?) end", htmldata) # Margins, top/bottom/left/right eg: <!-- pdf margins 2cm 2cm 2cm 2cm end --> margins = "2cm" mg = regex_one("pdf margins (.+?) end", htmldata) if mg != "": margins = mg header = "<!DOCTYPE html>\n<html>\n<head>" header += '<style>' header += '@page {size: %s %s; margin: %s}' % ( papersize, orientation, margins ) header += '</style>' header += "</head><body>" footer = "</body></html>" htmldata = htmldata.replace("font-size: xx-small", "font-size: 6pt") htmldata = htmldata.replace("font-size: x-small", "font-size: 8pt") htmldata = htmldata.replace("font-size: small", "font-size: 10pt") htmldata = htmldata.replace("font-size: medium", "font-size: 14pt") htmldata = htmldata.replace("font-size: large", "font-size: 18pt") htmldata = htmldata.replace("font-size: x-large", "font-size: 24pt") htmldata = htmldata.replace("font-size: xx-large", "font-size: 36pt") # Remove any img tags with signature:placeholder/user as the src htmldata = re.sub(r'<img.*?signature\:.*?\/>', '', htmldata) # Fix up any google QR codes where a protocol-less URI has been used htmldata = htmldata.replace("\"//chart.googleapis.com", "\"http://chart.googleapis.com") # Switch relative document uris to absolute service based calls htmldata = fix_relative_document_uris(dbo, htmldata) # Do the conversion from xhtml2pdf import pisa out = bytesio() pdf = pisa.pisaDocument(stringio(header + htmldata + footer), dest=out) if pdf.err: raise IOError(pdf.err) return out.getvalue()