Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

create pdf and save as

By
walid
on 8/29/13, 5:51 AM 1,236 views

Hello, I managed to create a pdf file that contains a histogram, which is stored on the server. my problem is: I want to display the window "save as" in the browser to give customers the possibility to save the file locally and I do not know how

please help me

import string

from reportlab.lib.styles import getSampleStyleSheet from reportlab.lib.units import cm from reportlab.graphics.charts.barcharts import VerticalBarChart from reportlab.graphics.shapes import Drawing from reportlab.platypus import * from reportlab.lib import colors

elements = [] styles = getSampleStyleSheet() doc = SimpleDocTemplate('C:/nombre_panne.pdf')

    elements.append(box(Paragraph("Nombre de pannes",styles['Title'])))

    # A Spacer, fairly intuitively, occupies a certain amount of Space
    # in the document.
    elements.append(Spacer(0, 0.5 * cm))

    # Create a chart 'Drawing'
    chart = VerticalBarChart()

    # Set the starting point to be (0, 0).  Changing this value changes
    # the position that the chart is rendered at within it's 'Drawing'
    # space, which we create below.
    chart.x = 0
    chart.y = 0

    # This determines the width, in centimeters (you could use 'inch'
    # as well) of the chart on the paper, as well as the height.
    chart_width = 8*cm
    chart_height = 3*cm

    chart.height = chart_height
    chart.width = chart_width

    # The vertical ticks will be labeled from 0 with a value every
    # 15 units, spaced so that the maximum value is 60.
    chart.valueAxis.valueMin = 0
    chart.valueAxis.valueMax = 60
    chart.valueAxis.valueStep = 15

    # Put the labels at the bottom with an interval of 8 units,
    # -2 units below the axis, rotated 30 degrees from horizontal
    chart.categoryAxis.labels.dx = 8
    chart.categoryAxis.labels.dy = -2
    chart.categoryAxis.labels.angle = 30 

    # The text box's NE corner (top right) is located at the above
    # coordinate
    chart.categoryAxis.labels.boxAnchor = 'ne'

    # Our various horizontal axis labels
    catNames = ['Jan-06', 'Feb-06', 'Mar-06', 'Apr-06', 'May-06','Jun-06', 'Jul-06', 'Aug-06']
    chart.categoryAxis.categoryNames = catNames

    # Some random data to populate the chart with.
    chart.data = [(8, 5, 20, 22, 37, 28, 30, 47)]

    # Since the 'Chart' class itself isn't a 'Flowable', we need to
    # create a 'Drawing' flowable to contain it.  We want the basic
    # area to be the same size as the chart itself, so we will
    # initialize it with the chart's size.
    drawing = Drawing(chart_width, chart_height)
    drawing.add(chart)

    # Add the Chart containing Drawing to our elements list
    elements.append(box(drawing))

    elements.append(Spacer(0, 2 * cm))

    # Write the document to disk
    doc.build(elements)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 8/29/13, 5:51 AM
Seen: 1236 times
Last updated: 3/16/15, 8:10 AM