Coder Social home page Coder Social logo

Comments (34)

rlovtangen avatar rlovtangen commented on July 18, 2024

I am able to reproduce. Looks like something happened between Grails 3.0.7 and 3.0.8

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

The difference is that is that response.format is "pdf" in Grails 3.0.7 but "all" in Grails 3.0.8 (in WkhtmltopdfRenderer). Must have a look at the Grails source to see what changed between those versions.

from grails-wkhtmltopdf.

panchocofrest avatar panchocofrest commented on July 18, 2024

try to response.setContentType ("application/pdf") before render()

Saludos...

from grails-wkhtmltopdf.

PatrickHuetter avatar PatrickHuetter commented on July 18, 2024

+1, same problem here

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Seems to have been resolved by a change in mail plugin between 2.0.0.RC2 and 2.0.0.RC4.

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

I just tested it with brand new app. Now it creates an empty PDF
Grails Version: 3.1.1
Groovy Version: 2.4.5
JVM Version: 1.8.0_60

I just modified show method

def show(MyPdfTea myPdfTea) {
    println "------myPdfTea------show----------"+myPdfTea
    //respond myPdfTea

    response.setContentType ("application/pdf")
    render( filename:"File bla.pdf",
            view:"/myPdfTea/show",
            model:[myPdfTea:myPdfTea],
            //header:"/pdf/someHeader",
            //footer:"/pdf/someFooter",
            marginLeft:20,
            marginTop:35,
            marginBottom:20,
            marginRight:20,
            headerSpacing:10)
}

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

And if i comment out
response.setContentType ("application/pdf")
It will render normally as show

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Can you try 1.0.0.RC4 ?

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

I just tried. Still it is producing empty PDF
compile "org.grails.plugins:wkhtmltopdf:1.0.0.RC4"
any my action is

def show(MyPdfTea myPdfTea) {
    response.setContentType ("application/pdf")
    render( filename:"File bla.pdf",
            view:"/myPdfTea/show",
            model:[myPdfTea:myPdfTea],
            //header:"/pdf/someHeader",
            //footer:"/pdf/someFooter",
            marginLeft:20,
            marginTop:35,
            marginBottom:20,
            marginRight:20,
            headerSpacing:10)
}

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

The fix was to make sure response.format is pdf, not all, so you no longer need response.setContentType ("application/pdf") to get pdf output. Can you confirm that setContentType is no longer needed?

Now I also get an empty pdf. Looks like a different issue.
I get this error message in console:

ERROR org.grails.plugins.wkhtmltopdf.WkhtmltoxExecutor - QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)

Do you get the same error?

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

This shows a normal show not a pdf.
http://localhost:8080/myPdfTea/show/1

def show(MyPdfTea myPdfTea) {
    println "--> show pdf tea <---"
    //response.setContentType ("application/pdf")
    render( filename:"File bla.pdf",
            view:"/myPdfTea/show",
            model:[myPdfTea:myPdfTea],
            //header:"/pdf/someHeader",
            //footer:"/pdf/someFooter",
            marginLeft:20,
            marginTop:35,
            marginBottom:20,
            marginRight:20,
            headerSpacing:10)
}

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Try to put ${response.format} in the view. Does it output "pdf" or "all"?

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

I changed the code a bit. But still the same. "mypdfaction" contains only one line "${response.format}" . Result is a white page.
Could it be because i have no header and no footer?

def mypdfaction (MyPdfTea myPdfTea){
    println "--> mypdfaction <---"
    //response.setContentType ("application/pdf")
    render( filename:"File bla.pdf",
            view:"/myPdfTea/mypdfaction",
            model:[myPdfTea:myPdfTea],
            //header:"/pdf/someHeader",
            //footer:"/pdf/someFooter",
            marginLeft:20,
            marginTop:35,
            marginBottom:20,
            marginRight:20,
            headerSpacing:10)
}

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Shouldn't need a header and footer.
Try adding println response.format before render. Does it print all or pdf?
If all, do you have other plugins installed?

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Result is a white page.

White pdf or white HTML response?

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

This action

def mypdfaction (MyPdfTea myPdfTea){
    println "--> mypdfaction <---"
    println response.format
    //response.setContentType ("application/pdf")
    render( filename:"File bla.pdf",
            view:"/myPdfTea/mypdfaction",
            model:[myPdfTea:myPdfTea],
            //header:"/pdf/someHeader",
            //footer:"/pdf/someFooter",
            marginLeft:20,
            marginTop:35,
            marginBottom:20,
            marginRight:20,
            headerSpacing:10)
}

view contains only one line

${response.format}

and the url

http://localhost:8080/myPdfTea/mypdfaction/1

Produces a white page. No pdf. And console out put is

--> mypdfaction <---
all

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

URL needs to be http://localhost:8080/myPdfTea/mypdfaction/1.pdf

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

Do i have to configure plugin?
I already have installed in my mac

wkhtmltopdf -V
wkhtmltopdf 0.12.2.1 (with patched qt)

now url

http://localhost:8080/myPdfTea/mypdfaction/1.pdf

produces error. From console

--> mypdfaction <---
pdf
ERROR org.grails.web.errors.GrailsExceptionResolver - WkhtmltoxException occurred when processing request: [GET] /myPdfTea/mypdfaction/1.pdf
Cannot find wkhtmltopdf executable at /usr/bin/wkhtmltopdf. Stacktrace follows:
org.grails.plugins.wkhtmltopdf.WkhtmltoxException: Cannot find wkhtmltopdf executable at /usr/bin/wkhtmltopdf
at com.me.MyPdfTeaController.mypdfaction(MyPdfTeaController.groovy:25) ~[main/:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96) ~[grails-core-3.1.1.jar:3.1.1]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.1.1.jar:3.1.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

in mac it is installed in

which wkhtmltopdf
/usr/local/bin/wkhtmltopdf

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Yes, add

grails.plugin.wkhtmltopdf.binary = "/usr/local/bin/wkhtmltopdf"

to application.groovy or corresponding property to application.yml if you prefer yml.

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

I added application.groovy and not it create a file called "File" no extension. Renamed the "File" to "File.pdf" and opened it. It is blank PDF. Here is console output.

--> mypdfaction <---
pdf
ERROR org.grails.plugins.wkhtmltopdf.WkhtmltoxExecutor - QFont::setPixelSize: Pixel size <= 0 (0)
QFont::setPixelSize: Pixel size <= 0 (0)

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

Command line works perfectly well
$ wkhtmltopdf http://localhost:8080/myPdfTea/show/1 my.pdf

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Good, then at least a pdf is created and we're getting the same error. Have no idea what the QFont error is. Any help is appreciated.

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

Maybe related.
QFont::setPixelSize

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

The QFont issue is caused by zoom being set to 0.0 due to the fix for #8. The comment for zoom says "default 1", but results in "--zoom, 0.0" in the argument list. I need to find out how to set default zoom to 1 or disable zoom property again. In the meantime, try adding zoom:1.0 as parameter to render.

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Should be fixed in 1.0.0.RC5

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

With RC5 i am getting different error.

ERROR org.grails.web.errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /myPdfTea/mypdfaction/1.pdf
Could not locate mail body /myPdfTea/show/1. Is it in a plugin? If so you must pass the plugin name in the [plugin] variable. Stacktrace follows:
java.lang.IllegalArgumentException: Could not locate mail body /myPdfTea/show/1. Is it in a plugin? If so you must pass the plugin name in the [plugin] variable
at grails.plugins.mail.MailMessageContentRenderer.createTemplate(MailMessageContentRenderer.groovy:95) ~[mail-2.0.0.RC6.jar:na]
at grails.plugins.mail.MailMessageContentRenderer$_render_closure1.doCall(MailMessageContentRenderer.groovy:58) ~[mail-2.0.0.RC6.jar:na]
at grails.plugins.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:174) ~[mail-2.0.0.RC6.jar:na]
at grails.plugins.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:57) ~[mail-2.0.0.RC6.jar:na]
at com.me.MyPdfTeaController$$EPfQbamu.mypdfaction(MyPdfTeaController.groovy:28) ~[na:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:96) ~[grails-core-3.1.1.jar:3.1.1]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.1.1.jar:3.1.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

But ${response.format} create a pdf with "all" in it.

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Tested 1.0.0.RC5 in Grails 3.1.1 and had no problems. In 3.1.1 I get 'pdf' for println response.format in controller but 'all' for ${response.format} in view. But as long as the controller thinks the format is pdf it should work.
Do you have any other non default plugins installed?

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024

I just created a test project with one domain and added 1.0.0.RC5 to Grails 3.1.1. My expectation it to convert the view of an object "/myPdfTea/show/1" into PDF.

From command line works perfectly.
wkhtmltopdf http://localhost:8080/myPdfTea/show/1 my.pdf

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

Can you show the content of the show method?

from grails-wkhtmltopdf.

arjangch avatar arjangch commented on July 18, 2024
def show(MyPdfTea myPdfTea) {
    println "--> show <---"
    respond myPdfTea
}

from grails-wkhtmltopdf.

rlovtangen avatar rlovtangen commented on July 18, 2024

I see. There is currently no support for that. You need to call render with a file name and view + other params.
Could possibly enhance WkhtmltoxService.makePdf(config) called from WkhtmltopdfRenderer to use a default file name and params and try to generate pdf for all requests that has pdf as response.format.

from grails-wkhtmltopdf.

Pritesh12 avatar Pritesh12 commented on July 18, 2024

Generating pdf with blank data.

from grails-wkhtmltopdf.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.