def print_pdf(request, tag_id, type): from reportlab.pdfgen.canvas import Canvas from labels.pdf_templates import LabelPDF #Letter is a paper format, you can import A4 for example from reportlab.lib.pagesizes import letter tag = get_object_or_404(Tag, pk=tag_id) #name of the pdf fname = "mylabels.pdf" #Generating response for file response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename=%s' %(fname) #creating the canvas object. You can change "letter" with another paper type c = Canvas(response, pagesize=letter) #LabelPDF is the class in pdf_templates that draws on the pdf pdf = LabelPDF(tag,type) #pdf.showBoundary=1 # Turns this on for debugging purposes. c = pdf.draw_frames(c) c.save() return response tv = {'tag_id':tag_id} return render_to_response("labels/print.html",tv)
def print_pdf(request, tag_id, type): from reportlab.pdfgen.canvas import Canvas from labels.pdf_templates import LabelPDF #Letter is a paper format, you can import A4 for example from reportlab.lib.pagesizes import letter tag = get_object_or_404(Tag, pk=tag_id) #name of the pdf fname = "mylabels.pdf" #Generating response for file response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename=%s' % (fname) #creating the canvas object. You can change "letter" with another paper type c = Canvas(response, pagesize=letter) #LabelPDF is the class in pdf_templates that draws on the pdf pdf = LabelPDF(tag, type) #pdf.showBoundary=1 # Turns this on for debugging purposes. c = pdf.draw_frames(c) c.save() return response tv = {'tag_id': tag_id} return render_to_response("labels/print.html", tv)
def print_pdf(request, tag_id, type): from reportlab.pdfgen.canvas import Canvas from labels.pdf_templates import LabelPDF from reportlab.lib.pagesizes import letter tag = get_object_or_404(Tag, pk=tag_id) fname = "mylabels.pdf" response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=%s' %(fname) c = Canvas(response, pagesize=letter) pdf = LabelPDF(tag,type) #pdf.showBoundary=1 # Turns this on for debugging purposes. c = pdf.draw_frames(c) c.save() return response tv = {'tag_id':tag_id} return render_to_response("labels/print.html",tv)