Depending on what you need to do....
You could shell down and run FOP from Apache foundation which is xml,
xslt to pdf
Or if you are filling in a form, you can use Adobe LiveCycle to define a
form and use code like below to fill in the form

def getPDFContent(id):
        values = getAllValues(id)
        code = values['CODE']
        completedfdf = getCompletedForm(values)
        pdffilename = PDFTemplateMapper.get(code, None)
        if pdffilename==None:
            raise "No PDF Template defined for %s" % code
        pdfpath = os.path.join(ThisDirectory, 'forms')
        pdfpath = os.path.join(pdfpath, pdffilename)
        pdftk = ["/usr/bin/pdftk" ,'pdftk'][os.name=='nt']
        cmd = '%s %s fill_form - output - flatten' % (pdftk, pdfpath)
        proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
shell=True, bufsize=100000000)
        cmdout,cmderr = proc.communicate(completedfdf)
        if cmderr != '':
            raise cmderr
        return cmdout

-----Original Message-----
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of Jirka Vejrazka
Sent: Thursday, November 18, 2010 4:14 AM
To: django-users@googlegroups.com
Subject: Re: ReportLab and Django - templates? ; FK object has no
attribute split

Hi Victor,

  It really depends on complexity of your PDF. I needed to do
something similar some time ago and used ReportLab addon called "pisa"
and used standard Django template language to define the PDF contents.

  You might want to take a look, it worked well enough for simple PDF
pages.

  Cheers

    Jirka

On 18/11/2010, Victor Hooi <victorh...@gmail.com> wrote:
> Hi,
>
> I'm trying to use ReportLab to produce a PDF output for one of my
> views.
>
> My first question is - at the moment, I'm building up the PDF inside
> my view. Is this really the recommended way of doing it? It's like
> I've got presentation code inside my view (controller). Isn't there a
> cleaner way of doing it, or going from a template to PDF somehow? (I
> know ReportLab offers a commercial package using RML templates,
> however I was hoping for an opensource/free method).
>
> Second question, I have a model with several FK fields. E.g.
>
>     class Article(models.Model):
>         category = models.ForeignKey(Category)
>         subject = models.ForeignKey(Subject)
>
> Both the category and subject classes have fields called "name", and
> __unicode__ methods defined which return name.
>
> I'm trying to refer to these fields in my PDF output. I have a list of
> items in article_list (i.e. queryset):
>
>     for item in article_list:
>         text = item.category
>         category = Paragraph(text, styles['Heading2'])
>         story.append(category)
>
>         text = '%s' % item.subject
>         subject = Paragraph(text, styles['Heading3'])
>         story.append(subject)
>
> When I try to run this code, I get:
>
>     'Category' object has no attribute 'split'
>
> and the same error with subject, obviously, once it gets to that bit
> of the code.
>
> Any idea why this might be, or how to fix it? Any help is much
> appreciated.
>
> Cheers,
> Victor
>
> --
> You received this message because you are subscribed to the Google
Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to