plainblack.com
Username Password
search
Bookmark and Share

    
Goto page «Previous Page   1 2    Next Page»

WebGUI::Content::PDFGenerator

User frodwith
Date 7/15/2011 3:22 pm
Views 18920
Rating -2    Rate [
|
]
Previous · Next
User Message
frodwith

If you've ever wanted WebGUI to generate PDFs of your pages for some reason (I've never understood the desire myself, but apparently it's a popular request), have a look at WebGUI::Content::PDFGenerator, which just landed in the master branch and will be in WebGUI 7.10.21 (not enabled by default). It uses WebKit and QT to render html pages to pdfs -- just add ?op=generatePdf to your page url. Feedback/patches welcome!



Back to Top
Rate [
|
]
 
 
martien

A great idea to use wkhtmltopdf.
The generator is working fine with wkhtmltopdf 0.10.0 rc2

I also started using it to generate complete Websitedocs and/or documenting a bunch of URLs.
( http://www.webgui-professional.de/websitedoc/website2pdfbook2 )

Your package could easily be changed/expanded to use wkhtmltoimage to generate snapshots too.



Back to Top
Rate [
|
]
 
 
martien

 Feedback/patches welcome!

How would you/ can you get a pdf of a page within the Account Module?

There's something like "?op=account;module=shop;do=viewTransaction;transactionId=AiVN95AJ-uDLIUP_9pL63w"

problems:

  • being logged-in
  • this link is already using an op
  • link is using javascript.


Back to Top
Rate [
|
]
 
 
scottwalters

 Feedback/patches welcome!

How would you/ can you get a pdf of a page within the Account Module?

There's something like "?op=account;module=shop;do=viewTransaction;transactionId=AiVN95AJ-uDLIUP_9pL63w"

problems:

  • being logged-in
  • this link is already using an op
  • link is using javascript.

Re: being logged in, if you're fetching the page with some robot (such as perhaps wget), WebGUI supports using HTTP Basic auth.  wget 'http://user|pass@webgui.site.com/protected/content' should work.

JavaScript on the page shouldn't be a problem as WebKit will simply run it and dynamic content is given a moment to settle before the pdf is generated.

Trying to mix and match two account plugins (op=) is a problem, though.  I don't have any suggestions there other than modifying the code to accept more parameters and kick-off dispatch again in various other ways than it does.



Back to Top
Rate [
|
]
 
 
vanjwilson

Getting this error in webgui.log when I try to generate a PDF of a page:

Can't use string ("--orientation Landscape") as an ARRAY ref while "strict refs" in use at /data/WebGUI/lib/WebGUI/Content/PDFGenerator.pm line 97

I'm using the default settings from the docs for PDFGenerator, but with "wkhtmltopdf" in the same directory as wre's perl:

   "pdfGen" :{
       "exe" : "/data/wre/prereqs/bin/wkhtmltopdf",
       "args" : "--orientation Landscape",
       "userId" : "_f7d61hs6djh0fjnxqw21",
       "cacheTimeout" : 60 # 1 minute cache timeout
   },

,  with wre, under Centos 5.5 64-bit



Back to Top
Rate [
|
]
 
 
martien

In the program it reads:

 my @args = (
        $o->{exe}, @{$o->{args} || []},
        '--cookie', $c->get('cookieName'), $login->getId,
        $url->getSiteURL . $url->gateway($url->getRequestedUrl),
        '-'
);


give your config a try with 

"args" : [ "--orientation", "Landscape" ],



Back to Top
Rate [
|
]
 
 
vanjwilson

@martien:

Your suggestion of putting brackets around the args in the WebGUI .conf file  to make them an array worked (e.g., "args" : [ "--orientation", "Landscape" ],).

Now that I can successfully create PDFs, I've run into a couple more issue:

1) I need to make PDFs of report pages, but when I add the "op=generatPdf" to my query string with the various search parameters, none of the other params get passed in the URL to wkhtmltopdf. The SQL report that comes back is not filtered at all. We are also using a custom macro to keep track of locations that our client wants query from page to page, and the custom macro is not running in the layout either.

2) For multi-page SQL reports, the PDF is only capturing the first page and the link list at the bottom. I think I may need to create a PDF-only copy of this page, with an SQL report that is not paginated, just to pass to GeneratePDF. Does that sound right?

3) Finally, the production server for this site is running on Mac OSX. I have installed wkhtmltopdf and gotten it to run by itself, but when I try to use the GeneratePDF content handler, I get this error in the modperl.error.log:

Fri Sep 16 14:36:42 minimac.*****.com wkhtmltopdf[47214] <Error>: kCGErrorRangeCheck: On-demand launch of the Window Server is allowed for root user only.
Fri Sep 16 14:36:42 minimac.*****.com wkhtmltopdf[47214] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.

Has anyone gotten this to work on a Mac server?



Back to Top
Rate [
|
]
 
 
martien

1) I need to make PDFs of report pages, but when I add the "op=generatPdf" to my query string with the various search parameters,

that's right, since you get the arguments only from the config.

2) For multi-page SQL reports, the PDF is only capturing the first page and the link list at the bottom. I think I may need to create a PDF-only copy of this page, with an SQL report that is not paginated, just to pass to GeneratePDF. Does that sound right?

yes

3) Finally, the production server for this site is running on Mac OSX. I have installed wkhtmltopdf and gotten it to run by itself, but when I try to use the GeneratePDF content handler, I get this error in the modperl.error.log:

Fri Sep 16 14:36:42 minimac.*****.com wkhtmltopdf[47214] <Error>: kCGErrorRangeCheck: On-demand launch of the Window Server is allowed for root user only.
Fri Sep 16 14:36:42 minimac.*****.com wkhtmltopdf[47214] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.

Has anyone gotten this to work on a Mac server?

Which version of wktohtml are you using?
The latest one doesn't need a running Xserver.
However you may use Xvfb as a headless server and call this:

#!/bin/bash
Xvfb :3  -fbdir /var/tmp 2>/dev/null &
export DISPLAY=":3.0";
sleep 3
/data/bin/wkhtmltopdf $* >> /tmp/pdfgen_wk.log 2>&1
sleep 1
killall Xvfb
rm -f /tmp/.X3-lock

Ofacourse you also can start Xvfb at boottime

Because all of the restrictions, I developed a new application, where it's possible to get more than one URL
or recursively get one URL and it's descendants.

Is that where you're looking for?

(s. http://www.webgui-professional.de/websitedoc/website2pdfbookAs an example, you'll find there temporarely a pdf with a 140 page WebGUI Webshop doc.
As a variant, there is also a possibility to make snapshots.)

Hope, this helps



Back to Top
Rate [
|
]
 
 
vanjwilson

@martien,

Thanks for the help.

I upgraded wkhtmltopdf to "0.10.0 rc2 static" for OSX, and now it works on our Mac server, too. (The docs for wkhtmltopdf give the details.)

The big issue now is the content handler not passing the query string from the URL, so that a filtered report page is returned.

I don't know WebGUI internals very well, but this code in PDFGenerator's "generate" sub seems like what I would need to modify to get params passed:

    my @args = (
        $o->{exe}, @{$o->{args} || []},
        '--cookie', $c->get('cookieName'), $login->getId,
        $url->getSiteURL . $url->gateway($url->getRequestedUrl),
        '-'
    );

(I might need to filter out the "op=generatePdf" in the query string.)

This seems similar to the issue you were having with the two "op" codes above.



Back to Top
Rate [
|
]
 
 
scottwalters

@martien,

Thanks for the help.

I upgraded wkhtmltopdf to "0.10.0 rc2 static" for OSX, and now it works on our Mac server, too. (The docs for wkhtmltopdf give the details.)

The big issue now is the content handler not passing the query string from the URL, so that a filtered report page is returned.

I don't know WebGUI internals very well, but this code in PDFGenerator's "generate" sub seems like what I would need to modify to get params passed:

    my @args = (
        $o->{exe}, @{$o->{args} || []},
        '--cookie', $c->get('cookieName'), $login->getId,
        $url->getSiteURL . $url->gateway($url->getRequestedUrl),
        '-'
    );

(I might need to filter out the "op=generatePdf" in the query string.)

This seems similar to the issue you were having with the two "op" codes above.

Yeah, I came to the same conclustion, that bit of code would need to be modified.  I took a stab at it but, beyond syntax tests, haven't tested it at all.  I may have time to test/debug later.  I've posted what I have here:

https://github.com/scrottie/webgui/blob/75de562325af2ded1f0297b654ab39dd2ca0d4e0/lib/WebGUI/Content/PDFGenerator.pm

That tries to send over all of the form paramters that it can, excluding the op parameter, of course.  You should be able to replace your copy of the file with this one.  If it works, I'd like to know about it so I can see about adding that change to core.

Thanks,

-scott



Back to Top
Rate [
|
]
 
 
     Goto page «Previous Page   1 2    Next Page»



© 2019 Plain Black Corporation | All Rights Reserved