Python reportlab.pdfgen.canvas.restoreState() Examples
The following are 16
code examples of reportlab.pdfgen.canvas.restoreState().
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.pdfgen.canvas
, or try the search function
.
Example #1
Source File: canvas.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def resetTransforms(self): """I want to draw something (eg, string underlines) w.r.t. the default user space. Reset the matrix! This should be used usually as follows:: canv.saveState() canv.resetTransforms() #...draw some stuff in default space coords... canv.restoreState() # go back! """ # we have to adjoin the inverse, since reset is not a basic operation (without save/restore) (selfa, selfb, selfc, selfd, selfe, selff) = self._currentMatrix det = selfa*selfd - selfc*selfb resulta = selfd/det resultc = -selfc/det resulte = (selfc*selff - selfd*selfe)/det resultd = selfa/det resultb = -selfb/det resultf = (selfe*selfb - selff*selfa)/det self.transform(resulta, resultb, resultc, resultd, resulte, resultf)
Example #2
Source File: canvas.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def restoreState(self): """restore the graphics state to the matching saved state (see saveState).""" self._code.append('Q') self.pop_state_stack() ############################################################### # # Drawing methods. These draw things directly without # fiddling around with Path objects. We can add any geometry # methods we wish as long as their meaning is precise and # they are of general use. # # In general there are two patterns. Closed shapes # have the pattern shape(self, args, stroke=1, fill=0); # by default they draw an outline only. Line segments come # in three flavours: line, bezier, arc (which is a segment # of an elliptical arc, approximated by up to four bezier # curves, one for each quadrant. # # In the case of lines, we provide a 'plural' to unroll # the inner loop; it is useful for drawing big grids ################################################################ #--------first the line drawing methods-----------------------
Example #3
Source File: para.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test2(canv,testpara): #print test_program; return from reportlab.lib.units import inch from reportlab.lib.styles import ParagraphStyle from reportlab.lib import rparsexml parsedpara = rparsexml.parsexmlSimple(testpara,entityReplacer=None) S = ParagraphStyle("Normal", None) P = Para(S, parsedpara) (w, h) = P.wrap(5*inch, 10*inch) print("wrapped as", (h,w)) canv.saveState() canv.translate(1*inch, 1*inch) canv.rect(0,0,5*inch,10*inch, fill=0, stroke=1) P.canv = canv canv.saveState() P.draw() canv.restoreState() canv.setStrokeColorRGB(1, 0, 0) #canv.translate(0, 3*inch) canv.rect(0,0,w,h, fill=0, stroke=1) canv.restoreState() canv.showPage()
Example #4
Source File: canvas.py From stdm with GNU General Public License v2.0 | 6 votes |
def resetTransforms(self): """I want to draw something (eg, string underlines) w.r.t. the default user space. Reset the matrix! This should be used usually as follows:: canv.saveState() canv.resetTransforms() #...draw some stuff in default space coords... canv.restoreState() # go back! """ # we have to adjoin the inverse, since reset is not a basic operation (without save/restore) (selfa, selfb, selfc, selfd, selfe, selff) = self._currentMatrix det = selfa*selfd - selfc*selfb resulta = selfd/det resultc = -selfc/det resulte = (selfc*selff - selfd*selfe)/det resultd = selfa/det resultb = -selfb/det resultf = (selfe*selfb - selff*selfa)/det self.transform(resulta, resultb, resultc, resultd, resulte, resultf)
Example #5
Source File: canvas.py From stdm with GNU General Public License v2.0 | 6 votes |
def restoreState(self): """restore the graphics state to the matching saved state (see saveState).""" self._code.append('Q') self.pop_state_stack() ############################################################### # # Drawing methods. These draw things directly without # fiddling around with Path objects. We can add any geometry # methods we wish as long as their meaning is precise and # they are of general use. # # In general there are two patterns. Closed shapes # have the pattern shape(self, args, stroke=1, fill=0); # by default they draw an outline only. Line segments come # in three flavours: line, bezier, arc (which is a segment # of an elliptical arc, approximated by up to four bezier # curves, one for each quadrant. # # In the case of lines, we provide a 'plural' to unroll # the inner loop; it is useful for drawing big grids ################################################################ #--------first the line drawing methods-----------------------
Example #6
Source File: para.py From stdm with GNU General Public License v2.0 | 6 votes |
def test2(canv,testpara): #print test_program; return from reportlab.lib.units import inch from reportlab.lib.styles import ParagraphStyle from reportlab.lib import rparsexml parsedpara = rparsexml.parsexmlSimple(testpara,entityReplacer=None) S = ParagraphStyle("Normal", None) P = Para(S, parsedpara) (w, h) = P.wrap(5*inch, 10*inch) print "wrapped as", (h,w) canv.saveState() canv.translate(1*inch, 1*inch) canv.rect(0,0,5*inch,10*inch, fill=0, stroke=1) P.canv = canv canv.saveState() P.draw() canv.restoreState() canv.setStrokeColorRGB(1, 0, 0) #canv.translate(0, 3*inch) canv.rect(0,0,w,h, fill=0, stroke=1) canv.restoreState() canv.showPage()
Example #7
Source File: generic_pdf.py From multiscanner with Mozilla Public License 2.0 | 6 votes |
def header_footer(self, canvas, doc): canvas.saveState() height_adjust = self.add_banner(canvas, doc) # Document Header if self.pdf_components.get('hdr_image', None) and self.firstPage: header = Image(self.pdf_components.get('hdr_image'), height=25 * mm, width=191 * mm) header.drawOn(canvas, doc.rightMargin, doc.height + doc.topMargin - 15 * mm) self.firstPage = False elif self.firstPage: header = Paragraph(self.pdf_components.get('hdr_html', ''), self.style['centered']) w, h = header.wrap(doc.width, doc.topMargin) header.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin - height_adjust * h) # Document Footer if self.pdf_components.get('ftr_image', None): footer = Image(self.pdf_components.get('ftr_image'), 8.5 * inch, 1.8 * inch) footer.drawOn(canvas, 0, 0) else: footer = Paragraph(self.pdf_components.get('ftr_html', ''), self.style['centered']) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, height_adjust * h) # Release the Canvas canvas.restoreState()
Example #8
Source File: generatereport.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def _header_footer(self, canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() style_right = ParagraphStyle(name='right', parent=self.bodystyle, fontName='arialuni', fontSize=10, alignment=TA_RIGHT) fieldsight_logo = Image('http://' + self.base_url +'/static/images/fs1.jpg') fieldsight_logo._restrictSize(1.5 * inch, 1.5 * inch) # headerleft = Paragraph("FieldSight", self.bodystyle) headerright = Paragraph(self.project_name, style_right) # w1, h1 = headerleft.wrap(doc.width, doc.topMargin) w2, h2 = headerright.wrap(doc.width, doc.topMargin) textWidth = stringWidth(self.project_name, fontName='arialuni', fontSize=10) fieldsight_logo.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 12) headerright.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 20) try: project_logo = Image(self.project_logo) project_logo._restrictSize(0.4 * inch, 0.4 * inch) project_logo.drawOn(canvas, headerright.width + doc.leftMargin -0.5 * inch - textWidth, doc.height + doc.topMargin + 10) except: pass # header.drawOn(canvas, doc.leftMargin + doc.width, doc.height + doc.topMargin +20) # Footer footer = Paragraph('Page no. '+str(canvas._pageNumber), style_right) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, h + 40) # Release the canvas canvas.restoreState()
Example #9
Source File: canvas.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def saveState(self): """Save the current graphics state to be restored later by restoreState. For example: canvas.setFont("Helvetica", 20) canvas.saveState() ... canvas.setFont("Courier", 9) ... canvas.restoreState() # if the save/restore pairs match then font is Helvetica 20 again. """ self.push_state_stack() self._code.append('q')
Example #10
Source File: para.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def end_at(self, x, y, para, canvas, textobject): offset = para.fontSize/8.0 canvas.saveState() color = self.color if self.color is None: color = para.fontColor canvas.setStrokeColor(color) canvas.line(self.xStart, self.yStart-offset, x,y-offset) canvas.restoreState()
Example #11
Source File: doctemplate.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def myLaterPages(canvas, doc): from reportlab.lib.colors import red PAGE_HEIGHT = canvas._pagesize[1] canvas.saveState() canvas.setStrokeColor(red) canvas.setLineWidth(5) canvas.line(66,72,66,PAGE_HEIGHT-72) canvas.setFont(_baseFontName,12) canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page) canvas.restoreState()
Example #12
Source File: report_delivery.py From callisto-core with GNU Affero General Public License v3.0 | 5 votes |
def get_header_footer(self, recipient): def func(canvas, doc): width, height = letter margin = 0.66 * 72 canvas.saveState() canvas.setFillColor("gray") canvas.drawString(margin, height - margin, "CONFIDENTIAL") canvas.drawRightString(width - margin, height - margin, str(timezone.now())) canvas.restoreState() return func
Example #13
Source File: canvas.py From stdm with GNU General Public License v2.0 | 5 votes |
def saveState(self): """Save the current graphics state to be restored later by restoreState. For example: canvas.setFont("Helvetica", 20) canvas.saveState() ... canvas.setFont("Courier", 9) ... canvas.restoreState() # if the save/restore pairs match then font is Helvetica 20 again. """ self.push_state_stack() self._code.append('q')
Example #14
Source File: para.py From stdm with GNU General Public License v2.0 | 5 votes |
def end_at(self, x, y, para, canvas, textobject): offset = para.fontSize/8.0 canvas.saveState() color = self.color if self.color is None: color = para.fontColor canvas.setStrokeColor(color) canvas.line(self.xStart, self.yStart-offset, x,y-offset) canvas.restoreState()
Example #15
Source File: doctemplate.py From stdm with GNU General Public License v2.0 | 5 votes |
def myLaterPages(canvas, doc): from reportlab.lib.colors import red PAGE_HEIGHT = canvas._pagesize[1] canvas.saveState() canvas.setStrokeColor(red) canvas.setLineWidth(5) canvas.line(66,72,66,PAGE_HEIGHT-72) canvas.setFont(_baseFontName,12) canvas.drawString(4 * inch, 0.75 * inch, "Page %d" % doc.page) canvas.restoreState()
Example #16
Source File: draw.py From cwg with GNU General Public License v3.0 | 5 votes |
def draw_vertical_text(canvas, font_name, font_size, xto, ymid, text): tw = stringWidth(text, font_name, font_size); canvas.setFont(font_name, font_size); canvas.saveState(); canvas.translate(xto, ymid - tw/2); canvas.rotate(90); canvas.drawString(0, 0, text); canvas.restoreState();