create pdf

A forum for general discussion of the Python programming language.

create pdf

Postby walid » Thu Aug 29, 2013 7:47 am

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

Code: Select all
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)

Last edited by Yoriz on Thu Aug 29, 2013 8:31 am, edited 2 times in total.
Reason: first post lock
walid
 
Posts: 2
Joined: Thu Aug 29, 2013 7:36 am

Re: create pdf

Postby micseydel » Thu Aug 29, 2013 8:49 am

They'll just have to right click a link and hit "save as". You can't control their browser beyond that, I don't think. Because I've never seen a site do what you want, they always just say to right click.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1116
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: create pdf

Postby walid » Thu Aug 29, 2013 9:03 am

I have a button that uses this function
walid
 
Posts: 2
Joined: Thu Aug 29, 2013 7:36 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests