0

I am from a non coding background so python, web2py is very new to me.

My app needs to export textarea content (using RTE redactor) to pdf. I get html content from textarea (redactor), can you please advice me on how to use pyfpdf to generate a pdf file on button click.

I don't know how to get the html content (images and text) on button click in view to generate pdf using appreport.

I was able to use app-report to generate a pdf (using PISA, PYPDF does not work) from an existing html file (without css) if html file has css it throws an error,

***<class 'sx.w3c.cssParser.CSSParseError'> Terminal function expression expected closing ')':: (u'Alpha(Opacity', u'=0); }\n\n\n\n.ui-state-')***

This might be due to a mistake in the controller code:

def myreport():
    html = response.render('myreport.html', dict())
    return plugin_appreport.REPORTPISA(html = html)

Another thing I tried was passing the html from my view to the controller using ajax post (in Javascript). Redactor is the textarea RTE I am using and alert gives me the desired html result.

View:

function getContent() {
var t= jQuery('#redactor_content').getCode();
alert(t);
jQuery.ajax({ 
                    type: "POST", 
                    url: "http://127.0.0.1:8000/Test50/default/myreport2", 
                    data: "{g : 'jQuery('#redactor_content').getCode()'}" 

                }); 
 }

Controller:

def myreport2():
    g = request.get_vars
    html = response.render(g)
    return plugin_appreport.REPORTPISA(html = html)

Due to my less knowledge in coding , I am not able to figure out and correct my mistake. I will be thankful if anybody can help me with this problem.

Regards, Akash

Akash
  • 19
  • 3

1 Answers1

0

Could it be this post request:

jQuery.ajax({ 
    type: "POST", 
    url: "http://127.0.0.1:8000/Test50/default/myreport2", 
    data: "{g : 'jQuery('#redactor_content').getCode()'}" 
  }); 
}

I think you should have the 'data' parameter be a literal dictionary, not a string. Change this line like this (remove all but one set of quotes):

    data: {g : jQuery('#redactor_content').getCode() }

This should properly send the request. The jQuery documentation says that the data parameter should be key-value pairs, not a string.

Kasapo
  • 5,294
  • 1
  • 19
  • 21
  • function getContent() { var t= jQuery('#redactor_content').getCode(); var l= JSON.stringify(t); jQuery.fileDownload('./myreport', { httpMethod :"GET", data: { cont : l} }); } I think using type:"GET" instead of "POST" is required in my scenario, I was confused about get and post. The above code worked but I had to use a jQuery plugin jquery.fileDownload.js to get the code working. I will keep in mind your suggestion and will try it. – Akash Jul 31 '12 at 09:18