def test6(self): d = Drawing(200, 100) d.add(Rect(1, 1, d.width - 2, d.height - 2, strokeWidth=2, strokeColor=toColor('red'), fillColor=toColor('lightblue')), name='bg0') def addImage(x, y, w, h): img = Image(x, y, w, h, IMAGENAME) d.add(Rect(img.x - 1, img.y - 1, img.width + 2, img.height + 2, strokeWidth=2, strokeColor=toColor('green'), fillColor=toColor('black')), name='bg1') d.add(img) addImage(40, 60, 55, 22) addImage(10, 10, 110, 44) d.translate(72, 6 * 72) self.IMAGES.append(d)
def test5(self): "Test convert a greyscale +alpha bitmap file as Image shape into a tmp. PDF file." d = Drawing(48, 48) img = Image(0, 0, 48, 48, GAIMAGE) d.add(img) d.translate(72, 4 * 72) self.IMAGES.append(d)
def test4(self): "Test convert a greyscale bitmap file as Image shape into a tmp. PDF file." d = Drawing(110, 44) img = Image(0, 0, 110, 44, GSIMAGE) d.add(img) d.translate(0, 2 * 72) self.IMAGES.append(d)
def test4(self): "Test convert a greyscale bitmap file as Image shape into a tmp. PDF file." d = Drawing(110, 44) img = Image(0, 0, 110, 44, GSIMAGE) d.add(img) d.translate(0,2*72) IMAGES.append(d)
def crearDrawing(grafico): x1, y1, x2, y2 = grafico.getBounds() w = x2-x1 h = y2-y1 dibujo = Drawing(w, h) dibujo.add(grafico) dibujo.translate(-x1, -y1) return dibujo
def test5(self): "Test convert a greyscale +alpha bitmap file as Image shape into a tmp. PDF file." d = Drawing(48, 48) img = Image(0, 0, 48, 48, GAIMAGE) d.add(img) d.translate(72,4*72) IMAGES.append(d) IMAGES.append(None) # used to indicate last test
def test2(self): "Test scaled Image shape adding it to a PDF page." inPath = IMAGENAME img = Image(0, 0, 110, 44, inPath) d = Drawing(110, 44) d.add(img) d.translate(120, 0) d.scale(2, 2) IMAGES.append(d)
def test2(self): "Test scaled Image shape adding it to a PDF page." inPath = IMAGENAME img = Image(0, 0, 110, 44, inPath) d = Drawing(110, 44) d.add(img) d.translate(120, 0) d.scale(2, 2) self.IMAGES.append(d)
def test3(self): "Test rotated Image shape adding it to a PDF page." inPath = IMAGENAME img = Image(0, 0, 110, 44, inPath) d = Drawing(110, 44) d.add(img) d.translate(420, 0) d.scale(2, 2) d.rotate(45) IMAGES.append(d) IMAGES.append(None) # used to indicate last test
from reportlab.graphics.shapes import Image, Drawing from reportlab.graphics import renderPDF from reportlab.lib.pagesizes import A4 imaxes = [] imaxe = Image(150, 50, 589, 202, "/home/dam2a/Descargas/vaca-lechera.jpg") debuxo = Drawing(500, 102) debuxo.translate(0, 650) #movelo de posición debuxo.add(imaxe) debuxo2 = Drawing(250, 51) debuxo2.add(imaxe) debuxo2.rotate(45) debuxo2.scale(0.5, 1.5) debuxo2.translate(150, -45) imaxes.append(debuxo2) imaxes.append(debuxo) documento = Drawing(A4[0], A4[1]) for elemento in imaxes: documento.add(elemento) renderPDF.drawToFile(documento, "segundoInforme.pdf")
from reportlab.graphics.shapes import Image, Drawing from reportlab.graphics import renderPDF from reportlab.lib.pagesizes import A4 imaxes = [] imaxe = Image(400, 0, 596, 133, "/home/manuel/Imaxes/200.jpg") debuxo = Drawing(30, 30) debuxo.add(imaxe) debuxo.translate(0, 0) imaxes.append(debuxo) debuxo = Drawing(30, 30) debuxo.add(imaxe) debuxo.scale(1.5, 0.5) debuxo.translate(-300, 300) debuxo.rotate(45) imaxes.append(debuxo) debuxo = Drawing(30, 30) debuxo.add(imaxe) debuxo.rotate(theta=60) debuxo.translate(-400, 00) imaxes.append(debuxo) debuxo = Drawing(A4[0], A4[1]) for aux in imaxes: debuxo.add(aux)
from reportlab.graphics.shapes import Image, Drawing from reportlab.graphics import renderPDF from reportlab.lib.pagesizes import A4 imaxes = [] imaxe = Image(0, 0, 500, 102, "/home/manuel/Descargas/logoCole.jpg") debuxo = Drawing(500, 102) debuxo.translate(0, 700) debuxo.add(imaxe) imaxes.append(debuxo) debuxo2 = Drawing(250, 51) debuxo2.add(imaxe) debuxo2.rotate(45) debuxo2.translate(500, 50) debuxo2.scale(0.5, 1.5) imaxes.append(debuxo2) documento = Drawing(A4[0], A4[1]) for elemento in imaxes: documento.add(elemento) renderPDF.drawToFile(documento, "segundoInforme.pdf")
for model_name in os.listdir(path): # Only visible dirs if model_name[0] == ".": continue # Generate qr code qrw = QrCodeWidget(model_name) b = qrw.getBounds() w = b[2] - b[0] h = b[3] - b[1] d = Drawing(1, 1, transform=[5, 0, 0, 5, 0, 0]) d.rotate(90) d.translate(0, -90) d.add(qrw) # Generate the rectangle r = Rect(1, 1, 1, 1) renderPDF.draw(d, p, 0, 0) #renderPDF.draw(r, p, 0, 0) x_offset = 0 y_offset = 2 o = 30 a = 390 w = 30
def auction_qr_codes(request, pk): user = request.user admin = False try: auction = Auction.objects.get(pk=pk) except Auction.DoesNotExist: raise Http404( "The auction you are trying to view does not exist or may have been deleted" ) if user.is_admin(auction.pk): admin = True buffer = io.BytesIO() # 612.0 x 792.0 (letter size) p = canvas.Canvas(buffer, pagesize=letter) x_res = 612 y_res = 792 include_images = 'include_images' in request.POST num_rows = 4 num_cols = 2 if include_images: num_rows = 2 num_cols = 2 block_width = x_res / num_cols block_height = y_res / num_rows image_width = 170 image_height = 170 qr_width = 130 qr_height = 130 text_size = 20 space_between = (block_height - qr_height - text_size) / 3 if include_images: space_between = (block_height - image_height - qr_height - text_size) / 4 index = 0 # Draw divider lines on first page for r in range(1, num_rows): for c in range(1, num_cols): p.line(c * block_width, 0, c * block_width, y_res) p.line(0, r * block_height, x_res, r * block_height) p.setFont("Times-Roman", text_size) for item in auction.item_set.all(): if index != 0 and index % (num_rows * num_cols) == 0: # Change to new page, draw divider lines, and reset font p.showPage() for r in range(1, num_rows): for c in range(1, num_cols): p.line(c * block_width, 0, c * block_width, y_res) p.line(0, r * block_height, x_res, r * block_height) p.setFont("Times-Roman", text_size) # Generate QR code from item page URL page_url = request.build_absolute_uri( reverse('auction:item', args=(item.id, ))) qrw = QrCodeWidget(page_url) b = qrw.getBounds() w = b[2] - b[0] h = b[3] - b[1] d = Drawing() d.add(qrw) # Bottom left corner of block x_offset = (index % num_cols) * block_width y_offset = (num_rows - 1 - (index // num_cols) % num_rows) * block_height # Draw QR code d.translate(x_offset + block_width / 2 - qr_width / 2, y_offset + space_between) d.scale(qr_width / w, qr_height / h) renderPDF.draw(d, p, 1, 1) # Draw item name p.drawCentredString( x_offset + block_width / 2, y_offset + block_height - text_size - space_between, item.name) if include_images: # Draw item image p.drawImage(settings.BASE_DIR + item.image.url, x_offset + x_res / 4 - image_width / 2, y_offset + qr_height + 2 * space_between, image_width, image_height) index += 1 p.save() buffer.seek(0) # Return rendered PDF file return FileResponse(buffer, as_attachment=True, filename='QR Codes Printout.pdf')
from reportlab.graphics import renderPDF from reportlab.graphics.shapes import Image, Drawing from reportlab.lib.pagesizes import A4 guion = [] imagen = Image( 400, 10, 596, 133, "/home/local/DANIELCASTELAO/fsancheztemprano/Imágenes/triforce.jpg") dibujo = Drawing(30, 30) dibujo.add(imagen) dibujo.translate(0, 600) guion.append(dibujo) dibujo = Drawing(30, 30) dibujo.add(imagen) dibujo.rotate(45) dibujo.scale(1.5, 0.5) dibujo.translate(-90, 300) guion.append(dibujo) dibujo = Drawing(30, 30) dibujo.add(imagen) dibujo.rotate(90) dibujo.translate(-20, -100) guion.append(dibujo) dibujo = Drawing(A4[0], A4[1]) for deb in guion: dibujo.add(deb)
for model_name in os.listdir(path): # Only visible dirs if model_name[0] == ".": continue # Generate qr code qrw = QrCodeWidget(model_name) b = qrw.getBounds() w=b[2]-b[0] h=b[3]-b[1] d = Drawing(1,1,transform=[5,0,0,5,0,0]) d.rotate(90) d.translate(0,-90) d.add(qrw) # Generate the rectangle r = Rect(1,1,1,1) renderPDF.draw(d, p, 0, 0) #renderPDF.draw(r, p, 0, 0) x_offset = 0; y_offset = 2; o = 30 a = 390 w = 30
from reportlab.graphics.shapes import Image, Drawing from reportlab.graphics import renderPDF from reportlab.lib.pagesizes import A4 guion = [] imaxe = Image(400,10,596,133,"hackerman.png") debuxo = Drawing(30,30) debuxo.add(imaxe) debuxo.translate(0, 600) guion.append(debuxo) debuxo = Drawing(30,30) debuxo.add(imaxe) debuxo.rotate(45) debuxo.scale(1.5, 0.5) debuxo.translate(-90, 300) guion.append(debuxo) debuxo = Drawing(30,30) debuxo.add(imaxe) debuxo.rotate(90) debuxo.translate(-20, -100) guion.append(debuxo) debuxo = Drawing(A4[0], A4[1]) for deb in guion: debuxo.add(deb) renderPDF.drawToFile(debuxo, "proba2.pdf")
0, side_thickness, side_depth, strokeWidth=0.02, fillColor=colors.white)) rightsidetop.translate(bottom_width, side_height) rightsidetop.shift(bottom_width, side_height) rightsidetop.skew(iso_angle, 0) # Comment out the following 3 lines to see the full bottom panel, which # is partially hidden behind the side panel when it is drawn on top. d.add(rightsidefront) d.add(rightoutside) d.add(rightsidetop) d.translate(20, 20) renderPDF.drawToFile(d, 'out/drawing.pdf', 'My first drawing') cabs = cabinet.Run(247, 28.5, 24) # 3D model of a cabinet is a graph of points (vertices), some of which are # connected by lines (edges). # Points (vertices) are numbered 0, 1, 2,..., in order from left to right, top # to bottom, front to back. A point's number is its position in the list. # Start with a cube: # +z # |
[2, 4, 7], [3, 5, 6]] # Construct a list of lines from the graph model of the cabinet: lines = [(p1, p2) for p1 in range(len(cab_pts)) for p2 in cab_edges[p1]] # Change from vertex numbers to coordinates in 3D space lines_3D = [(cab_pts[p1], cab_pts[p2]) for p1, p2 in lines] if debug: print('lines_3D=' + str(lines_3D)) # Rotate & project isometric_lines = [(tuple(np.matmul(y_rot, np.matmul(z_rot, p1))[1:].tolist()), tuple(np.matmul(y_rot, np.matmul(z_rot, p2))[1:].tolist())) for p1, p2 in lines_3D] if debug: print('isometric_lines=' + str(isometric_lines)) d2 = Drawing() # Add all the lines to the drawing. for p1, p2 in isometric_lines: d2.add(Line(p1[0], p1[1], p2[0], p2[1], strokeWidth=0.3)) # Move the cabinet away from the lower-left corner d2.translate(40, 40) renderPDF.drawToFile(d2, 'rotated.pdf', 'Rotated View of Cabinet') # matrix_ops.py ends here