本文整理汇总了Python中reportlab.pdfgen.canvas.showPage函数的典型用法代码示例。如果您正苦于以下问题:Python showPage函数的具体用法?Python showPage怎么用?Python showPage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了showPage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_cards
def print_cards():
#LETTER = (8.5, 11)
LETTER = (11, 8.5)
DPI = 72
# Set print margins
MARGIN = 0.5
x_offset = int(MARGIN * DPI)
y_offset = int(MARGIN * DPI)
CARDSIZE = (int(2.49 * DPI), int(3.48 * DPI))
#scale = CARDSIZE[0] / 375.0 # Default cardsize in px
cards = convert_to_cards(session['cardtext'])
byte_io = BytesIO()
from reportlab.pdfgen import canvas
canvas = canvas.Canvas(byte_io, pagesize=landscape(letter))
WIDTH, HEIGHT = landscape(letter)
#draw = ImageDraw.Draw(sheet)
for card in cards:
image = create_card_img(card,session["do_google"])
image_reader = ImageReader(image)
canvas.drawImage(image_reader,
x_offset,
y_offset,
width=CARDSIZE[0],
height=CARDSIZE[1])
x_offset += CARDSIZE[0] + 5 # 5 px border around cards
if x_offset + CARDSIZE[0] > LETTER[0] * DPI:
x_offset = int(MARGIN * DPI)
y_offset += CARDSIZE[1] + 5
if y_offset + CARDSIZE[1] > LETTER[1] * DPI:
x_offset = int(MARGIN * DPI)
y_offset = int(MARGIN * DPI)
canvas.showPage()
canvas.save()
byte_io.seek(0)
return send_file(byte_io, mimetype='application/pdf')
示例2: produce_pdf
def produce_pdf(self, input_file=None, out_directory=None):
out = os.path.join(out_directory, self.out_file_name)
self.data = self._parse_input_file(input_file)
canvas = reportlab.pdfgen.canvas.Canvas(out, pagesize=pagesizes.A4)
map(lambda p: self._process_page(canvas, p), self.pages)
canvas.showPage()
canvas.save()
示例3: make_page
def make_page(canvas, config, page):
#print ' ', page
caption_height = place_caption(canvas, config, page['caption'])
if 'image' in page:
place_images(canvas, config, page, caption_height)
canvas.showPage()
示例4: genBarcode
def genBarcode(code, value, canvas, scale):
dr = createBarcodeDrawing(code, value=value, humanReadable=True)
dr.renderScale = scale
bounds = dr.getBounds()
width = bounds[2] - bounds[0]
height = bounds[3] - bounds[1]
dr.drawOn(canvas, (297*mm)/2-width*scale/2, (210*mm)/2-height*scale/2)
canvas.drawString(1*mm, 1*mm, "generated at "+str(datetime.now()) + " from "+request.url)
canvas.showPage()
示例5: create_backpdf
def create_backpdf(image_name):
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
canvas = canvas.Canvas('PC_back.pdf')
canvas.setPageSize((6*inch, 4*inch))
canvas.drawImage(image_name, 0.1*inch, 0.1*inch, 5.9*inch, 3.9*inch)
canvas.showPage()
canvas.save()
示例6: create_mug_pdf
def create_mug_pdf(image_name):
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
canvas = canvas.Canvas('mug.pdf')
canvas.setPageSize((8.58*inch, 3.7*inch))
canvas.drawImage(image_name, 0.1*inch, 0.1*inch, 5.9*inch, 3.9*inch)
canvas.showPage()
canvas.save()
示例7: convert_pdf
def convert_pdf(image_name, width, height):
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
canvas = canvas.Canvas('output.pdf')
canvas.setPageSize((width*inch, height*inch))
canvas.drawImage(image_name, 0.1*inch, 0.1*inch, (width-0.1)*inch, (height-0.1)*inch)
canvas.showPage()
canvas.save()
示例8: gen_label
def gen_label(sku, canvas, title):
# barcode128 = code39.Extended39(value = sku, barWidth = barWidth, barHeight = barHeight)
barcode128 = code128.Code128(value = sku, barWidth = barWidth, barHeight = barHeight)
canvas.scale(0.3, 1.0)
barcode128.drawOn(canvas, bar_x, bar_y)
canvas.setFont(font, fontsize)
canvas.drawString(bar_value_x, bar_value_y, sku)
canvas.showPage()
示例9: print_image
def print_image(canvas, image, name):
w, h = A4
canvas.drawImage(
pil_to_rl(image, name),
0,
0,
height=w * 0.95,
width=w * 0.95,
preserveAspectRatio=True,
anchor='sw'
)
canvas.drawCentredString(w / 2, 600, name)
canvas.showPage()
canvas.save()
示例10: main
def main():
output_path = "../../data/characters/templates_printout.pdf"
canvas = reportlab.pdfgen.canvas.Canvas(
output_path, bottomup=1, pagesize=reportlab.lib.pagesizes.A4)
canvas_size = reportlab.lib.pagesizes.A4
width, height = canvas_size
# Size of image and margin between images on a pdf page
image_size = int(width * 0.2)
margin = int(width * 0.06)
paths = glob.glob("../../data/characters/templates/*.jpg")
templates = [cv2.cvtColor(cv2.imread(path), cv2.COLOR_BGR2GRAY) for path in paths]
temporary_dir = "/tmp/templates/"
# Make directory for temporary images if it doesn't already exist
os.makedirs(temporary_dir, exist_ok=True)
# Write bordered images to temporary dir
for path, template in zip(paths, templates):
temporary_path = temporary_dir + os.path.basename(path)
cv2.imwrite(temporary_path, template)
paths_iterator = iter(glob.glob(temporary_dir + "/*.jpg"))
# Create pages until we run out of template paths
while True:
try:
create_page(canvas, canvas_size, paths_iterator, image_size, margin)
canvas.showPage()
except StopIteration:
break
canvas.save()
# Clean up temporary images
shutil.rmtree(temporary_dir)
示例11: gentestlabels
def gentestlabels():
# ascertain edges
global gl_printer
(xwidth, yheight) = letter
margin = .3*inch
xwidth -= margin*2
yheight -= margin*2
xorg = yorg = margin
canvas = canvas_init('tmp/kitlabels.pdf',pagesize=letter,bottomup=1,verbosity=1)
canvas.setStrokeColorRGB(.33,.33,.33)
canvas.setFont('Helvetica',10)
yrows = 3
xcols = 2
ystep = yheight/yrows
xstep = xwidth/xcols
v('xystep: %f %f' % (xstep,ystep) )
x = xorg
i = 0
pages = 2
for page in range(pages):
if (page != 0):
canvas.showPage()
y = yheight-ystep+margin
for yrowcount in reversed(range(yrows)):
for xcolcount in reversed(range(xcols)):
genkitlabel(canvas, x,y,xstep,ystep,'',test=1)
i += 1
x += xstep
x = xorg
y -= ystep
finish_up(canvas)
exit()
示例12: test5
def test5(self):
"List and display all named colors and their gray equivalents."
canvas = reportlab.pdfgen.canvas.Canvas(outputfile('test_lib_colors.pdf'))
#do all named colors
framePage(canvas, 'Color Demo - page %d' % canvas.getPageNumber())
all_colors = reportlab.lib.colors.getAllNamedColors().items()
all_colors.sort() # alpha order by name
canvas.setFont('Times-Roman', 10)
text = 'This shows all the named colors in the HTML standard (plus their gray and CMYK equivalents).'
canvas.drawString(72,740, text)
canvas.drawString(200,725,'Pure RGB')
canvas.drawString(300,725,'B&W Approx')
canvas.drawString(400,725,'CMYK Approx')
y = 700
for (name, color) in all_colors:
canvas.setFillColor(colors.black)
canvas.drawString(100, y, name)
canvas.setFillColor(color)
canvas.rect(200, y-10, 80, 30, fill=1)
canvas.setFillColor(colors.color2bw(color))
canvas.rect(300, y-10, 80, 30, fill=1)
c, m, yel, k = colors.rgb2cmyk(color.red, color.green, color.blue)
CMYK = colors.CMYKColor(c,m,yel,k)
canvas.setFillColor(CMYK)
canvas.rect(400, y-10, 80, 30, fill=1)
y = y - 40
if y < 100:
canvas.showPage()
framePage(canvas, 'Color Demo - page %d' % canvas.getPageNumber())
canvas.setFont('Times-Roman', 10)
y = 700
canvas.drawString(200,725,'Pure RGB')
canvas.drawString(300,725,'B&W Approx')
canvas.drawString(400,725,'CMYK Approx')
canvas.save()
示例13: add_split_data
def add_split_data(canvas,title,data,page_limit):
data_list = data.split('\n')
data_list_lenght = len(data_list)
i = 0
x = TEXT_ORIGIN_X
y = TEXT_ORIGIN_Y
for i in range(data_list_lenght):
canvas.drawText(new_textobject(title,canvas,TITLE_X,TITLE_Y))
string = data_list[i] + '\n'
if string.find('*') != -1:
x = POS_TABS
canvas.drawText(new_textobject(string,canvas,x,y))
x = TEXT_ORIGIN_X
else:
canvas.drawText(new_textobject(string,canvas,x,y))
y = y - 15
if i % page_limit == 0 and i != 0:
canvas.showPage()
y = TEXT_ORIGIN_Y
canvas.showPage()
示例14: add_consensus
def add_consensus(canvas,title,data,page_limit=PAGE_LIMIT,line_limit=LINE_LIMIT):
data_lenght = len(data)
i = 0
j = 0
y = CONSENSUS_Y
x = CONSENSUS_X
string = ""
canvas.drawText(new_textobject(title,canvas,TITLE_X,TITLE_Y))
for i in range(data_lenght):
string = string + data[i]
if i % line_limit == 0 and i != 0:
canvas.drawText(new_textobject(string,canvas,x,y))
y = y - 15
string = ""
j = j + 1
if j % page_limit == 0 and j != 0:
canvas.showPage()
canvas.drawText(new_textobject(title,canvas,TITLE_X,TITLE_Y))
y = CONSENSUS_Y
j = 0
示例15: draw_page
def draw_page(page, uid, survey_name, canvas : reportlab.pdfgen.canvas.Canvas):
draw_qr_data(canvas, 'survey:'+survey_name+':'+page.name+':'+uid, 64, (48, height-64-48))
canvas.setFillColorRGB(0.2, 0.2, 0.2)
canvas.setStrokeColorRGB(0.2, 0.2, 0.2)
canvas.circle(32, 32, 4, stroke=1, fill=1)
canvas.circle(32+12, 32, 4, stroke=1, fill=1)
canvas.circle(32, 32+12, 4, stroke=1, fill=1)
canvas.circle(width - 32, height - 32, 4, stroke=1, fill=1)
canvas.circle(width - 32-12, height - 32, 4, stroke=1, fill=1)
canvas.circle(width - 32, height - 32-12, 4, stroke=1, fill=1)
canvas.circle(width - 32, 32, 4, stroke=1, fill=1)
canvas.circle(width - 32-12, 32, 4, stroke=1, fill=1)
canvas.circle(width - 32, 32+12, 4, stroke=1, fill=1)
canvas.circle(32, height - 32, 4, stroke=1, fill=1)
canvas.circle(32+12, height - 32, 4, stroke=1, fill=1)
canvas.circle(32, height - 32-12, 4, stroke=1, fill=1)
canvas.setFillColorRGB(0.3, 0.3, 0.3)
canvas.drawString(128, height - 67, survey_name+':'+page.name+':'+uid)
canvas.setFillColorRGB(0.4, 0.4, 0.4)
canvas.setStrokeColorRGB(0.2, 0.2, 0.2)
canvas.setFont('Courier', 8)
for field in page.get_binary_fields():
canvas.circle(field.position[0], height - field.position[1], 5, stroke=1, fill=0)
canvas.drawCentredString(field.position[0], height - field.position[1]-2, field.hint)
canvas.setFillColorRGB(0.1, 0.1, 0.1)
for text in page.get_text_areas():
if text.rotation != 0:
canvas.saveState()
canvas.rotate(text.rotation)
tobj = canvas.beginText(text.position[0], height - text.position[1])
tobj.setFont(text.fontname, text.fontsize)
for line in text.text.split():
tobj.textLine(line)
canvas.drawText(tobj)
if text.rotation != 0:
canvas.restoreState()
canvas.showPage()