本文整理汇总了Python中reportlab.pdfgen.canvas.Canvas方法的典型用法代码示例。如果您正苦于以下问题:Python canvas.Canvas方法的具体用法?Python canvas.Canvas怎么用?Python canvas.Canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reportlab.pdfgen.canvas
的用法示例。
在下文中一共展示了canvas.Canvas方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def __init__(self, text=[], target='your website', pdfName='Report.pdf'):
self.__target = target
self.__pdfName = self.__path + pdfName
self.__text = text
if not os.path.exists('result/'):
os.mkdir(r'result/')
time = datetime.datetime.today()
date = time.strftime("%h-%d-%Y %H:%M:%S")
c = canvas.Canvas(self.__pdfName)
c.setPageSize((16 * inch,22 * inch))
textobj = c.beginText()
textobj.setTextOrigin(inch, 20 * inch)
textobj.textLines('''
This is the scanning report of %s.
''' %self.__target)
textobj.textLines('''
Date: %s
''' % date)
for line in self.__text:
textobj.textLine(line.strip())
c.drawText(textobj)
c.showPage()
c.save()
示例2: build
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing, canvasmaker=canvas.Canvas):
"""build the document using the flowables. Annotate the first page using the onFirstPage
function and later pages using the onLaterPages function. The onXXX pages should follow
the signature
def myOnFirstPage(canvas, document):
# do annotations and modify the document
...
The functions can do things like draw logos, page numbers,
footers, etcetera. They can use external variables to vary
the look (for example providing page numbering or section names).
"""
self._calc() #in case we changed margins sizes etc
frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal')
self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize),
PageTemplate(id='Later',frames=frameT, onPage=onLaterPages,pagesize=self.pagesize)])
if onFirstPage is _doNothing and hasattr(self,'onFirstPage'):
self.pageTemplates[0].beforeDrawPage = self.onFirstPage
if onLaterPages is _doNothing and hasattr(self,'onLaterPages'):
self.pageTemplates[1].beforeDrawPage = self.onLaterPages
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
示例3: makeBarcodeFile
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
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()
示例4: __init__
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def __init__(self, display_form, letter_display=None, canvas=None):
self.file = io.BytesIO()
self.width, self.height = letter
self.canvas = canvas
if not canvas:
self.canvas = Canvas(
self.file,
pagesize=letter)
self.canvas.setAuthor('Clear My Record, Code for America')
self.frame = Margin(
u('1in'),
u('.75in'),
u('1in'),
u('.75in'))
self.form = display_form
self.letter = letter_display
self.cursor = Position(
self.frame.left,
self.height - self.frame.top
)
self.nice_date = \
self.form.date_received.get_current_value().strftime("%B %-d, %Y")
示例5: plot_6_plus
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def plot_6_plus(bases, output_path, project, c_draw):
for i in range(0,5):
c_draw.drawImage(output_path+"/SBS_sub_plots/"+bases[i][0] + "_" + project+".png", \
LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH)
c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%")
extra_sigs = "* "
for i in range(5, len(bases)-1):
extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), "
extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)"
c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs)
# Helper function to add calculations to layout
# Parameters:
# c_draw - (Canvas) The canvas to draw the graph decomposition on.
# statistics - (Pandas Dataframe) Dataframe w/ calculations
示例6: draw_statistics
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def draw_statistics(c_draw, statistics):
cos_sim = statistics["Cosine Similarity"][0]
cor_coeff = statistics["Correlation Coefficient"][0]
l1_norm_percent = statistics["L1 Norm %"][0]
l2_norm_percent = statistics["L2 Norm %"][0]
kl_divergence = statistics["KL Divergence"][0]
c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-90, \
"Cosine Similarity: " + str(cos_sim))
c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-100, \
"Correlation: " + str(cor_coeff))
c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-110, \
"L1 Error %: " + str(l1_norm_percent) + "%")
c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-120, \
"L2 Error %: " + str(l2_norm_percent) + "%")
c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-130, \
"KL Divergence: " + str(kl_divergence))
# Helper function to resize bracket depending on number of bases plotted
# Parameters:
# num_bases - (Integer) The number of bases to be plotted.
# c_draw - (Canvas) The canvas to draw the graph decomposition on.
示例7: draw_bracket
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def draw_bracket(num_bases, c_draw):
paths = cosmic.__path__[0]
num_plts = num_bases - 1
if(num_bases >= 5):
num_plts = 4
c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], mask='auto')
# Parameters:
# de_novo_name - (String) The name of the denovo signature.
# basis_names - (List of Strings) The names of the basis signatures
# output_path - (String) Path to where to save the output.
# project - (String) The project name that is appended to file names.
# c - (Canvas) The canvas that is being drawn on.
# reconstruction - (Boolean) True to create reconstruction
# statistics - (Pandas Dataframe) If reconstructing, then include statistics.
# Output:
# A graph of the de_novo signature's decomposition.
示例8: gen_decomposition
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics):
c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter)
c.setPageSize(landscape(letter))
c.setFont("Arial-Bold", 7.19)
basis_plots = []
for i in range(0,len(basis_names)):
basis_plots.append([basis_names[i], weights[i]])
# create for loop to iterate through list, then change second value in list of lists
# Otherwise sorts strings and then 5.14% > 48.54%
for j in range(0, len(basis_names)):
basis_plots[j][1] = float(basis_plots[j][1].strip("%"))
sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True)
gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics)
c.save()
示例9: plot_6_plus
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def plot_6_plus(bases, output_path, project, c_draw):
for i in range(0,5):
c_draw.drawImage(output_path+"/ID_sub_plots/"+bases[i][0] + "_" + project+".png", LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH)
c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%")
extra_sigs = "* "
for i in range(5, len(bases)-1):
extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), "
extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)"
c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) + 30, extra_sigs)
# Helper function to add calculations to layout
# Parameters:
# c_draw - (Canvas) The canvas to draw the graph decomposition on.
# statistics - (Pandas Dataframe) Dataframe w/ calculations
示例10: draw_bracket
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def draw_bracket(num_bases, c_draw):
paths = cosmic.__path__[0]
num_plts = num_bases - 1
if(num_bases >= 5):
num_plts = 4
c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, BRACKET_SIZES[num_plts][0], width = 15, height = BRACKET_SIZES[num_plts][1], mask='auto')
# Parameters:
# de_novo_name - (String) The name of the denovo signature.
# basis_names - (List of Strings) The names of the basis signatures
# output_path - (String) Path to where to save the output.
# project - (String) The project name that is appended to file names.
# c - (Canvas) The canvas that is being drawn on.
# reconstruction - (Boolean) True to create reconstruction
# statistics - (Pandas Dataframe) If reconstructing, then include statistics.
# Output:
# A graph of the de_novo signature's decomposition.
示例11: gen_decomposition
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics):
# Note: 0th index contains the title of the column
c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter)
c.setPageSize(landscape(letter))
c.setFont("Arial-Bold", 7.19)
basis_plots = []
for i in range(0,len(basis_names)):
basis_plots.append([basis_names[i], weights[i]])
# create for loop to iterate through list, then change second value in list of lists
# Otherwise sorts strings and then 5.14% > 48.54%
for j in range(0, len(basis_names)):
basis_plots[j][1] = float(basis_plots[j][1].strip("%"))
sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True)
gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics)
c.save()
示例12: plot_6_plus
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def plot_6_plus(bases, output_path, project, c_draw):
for i in range(0,5):
c_draw.drawImage(output_path+"/DBS_sub_plots/"+bases[i][0] + "_" + project+".png", \
LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH)
c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%")
extra_sigs = "* "
for i in range(5, len(bases)-1):
extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), "
extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)"
c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs)
# Helper function to add calculations to layout
# Parameters:
# c_draw - (Canvas) The canvas to draw the graph decomposition on.
# statistics - (Pandas Dataframe) Dataframe w/ calculations
示例13: draw_bracket
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def draw_bracket(num_bases, c_draw):
paths = cosmic.__path__[0]
num_plts = num_bases - 1
if(num_bases>= 5):
num_plts = 4
c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, \
BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], mask='auto')
# Parameters:
# de_novo_name - (String) The name of the denovo signature.
# basis_names - (List of Strings) The names of the basis signatures
# output_path - (String) Path to where to save the output.
# project - (String) The project name that is appended to file names.
# c - (Canvas) The canvas that is being drawn on.
# reconstruction - (Boolean) True to create reconstruction
# statistics - (Pandas Dataframe) If reconstructing, then include statistics.
# Output:
# A graph of the de_novo signature's decomposition.
示例14: draw_bracket
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def draw_bracket(num_bases, c_draw):
num_plts = num_bases - 1
if(num_bases >= 5):
num_plts = 4
c_draw.drawImage(paths+"src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, \
BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], \
mask='auto')
# Parameters:
# de_novo_name - (String) The name of the denovo signature.
# basis_names - (List of Strings) The names of the basis signatures
# output_path - (String) Path to where to save the output.
# project - (String) The project name that is appended to file names.
# c - (Canvas) The canvas that is being drawn on.
# reconstruction - (Boolean) True to create reconstruction
# statistics - (Pandas Dataframe) If reconstructing, then include statistics.
# Output:
# A graph of the de_novo signature's decomposition.
示例15: gen_decomposition
# 需要导入模块: from reportlab.pdfgen import canvas [as 别名]
# 或者: from reportlab.pdfgen.canvas import Canvas [as 别名]
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics):
# Note: 0th index contains the title of the column
c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter)
c.setPageSize(landscape(letter))
c.setFont("Arial-Bold", 7.19)
basis_plots = []
for i in range(0,len(basis_names)):
basis_plots.append([basis_names[i], weights[i]])
# create for loop to iterate through list, then change second value in list of lists
# Otherwise sorts strings and then 5.14% > 48.54%
for j in range(0, len(basis_names)):
basis_plots[j][1] = float(basis_plots[j][1].strip("%"))
sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True)
gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics)
c.save()