Kibana: Export to PDF

Created on 18 Sep 2013  ·  75Comments  ·  Source: elastic/kibana

Use PhantomJS to render images of a dashboard. These images then could be email/shared. All this could be scheduled.

rashidkpc came up with this idea the other day in IRC. There is an issue with AngularJS' routing though, and it does not work.

enhancement

All 75 comments

+1

Comments via IRC

[kubes] Ok, what do you think the issue is. Can you point me in the write direction and I take swing @ it.

[rashidkpc] basically you need to convince phantom JS to both wait for thr route to full resolve, as well as wait for all of the data to be loaded

[kubes] rashidkpc: Is there any element to check to tell if the data is loaded? If I have phantomjs just wait for N sec it works.. thinking of waiting for something...

[rashidkpc] kubes: not really, everything is async, and the panels operate independently, there's currently no way to tell if everything is "done"

here is a modified version of the example https://github.com/ariya/phantomjs/wiki/Screen-Capture

rasterize.js

Increase(added) the WaitTime to 10 seconds

var page = require('webpage').create(),
    system = require('system'),
    address, output, size;
//How to to wait for kibana to load and the data from elasticseatch in milliseconds.
var waitTime = 10 * 1000;

if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
    console.log('  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    page.viewportSize = { width: 1024, height: 1024 };
    if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
        size = system.args[3].split('*');
        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
                                           : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
    }
    if (system.args.length > 4) {
        page.zoomFactor = system.args[4];
    }
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit();
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, waitTime);
        }
    });
}

+1

When will this be supported? 2015?

Greetings Damien

For the records:

  • You don't need to use .setTimeout to make sure that a webpage has completely loaded before you'll call render. You can use onConsoleMessage event handler and pre-specific messages to communicate among Javascript inner code and outer script. And within Javascript you surely know you when are ready to render:
var page = require('webpage').create(),
    system = require('system'),
    address, output, size;
//How to to wait for kibana to load and the data from elasticseatch in milliseconds.
var waitTime = 10 * 1000;

if (system.args.length < 3 || system.args.length > 5) {
    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
    console.log('  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
    phantom.exit(1);
} else {
    address = system.args[1];
    output = system.args[2];
    page.viewportSize = { width: 1024, height: 1024 };
    if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
        size = system.args[3].split('*');
        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
                                        : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
    }
    if (system.args.length > 4) {
        page.zoomFactor = system.args[4];
    }
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
            phantom.exit();
        } else {
            page.onConsoleMessage = function(msg, lineNum, sourceId) {
                if (msg == 'done') {
                    page.render(output);
                    phantom.exit();
                }
            };
        }
    });
}
  • My experience with PhantomJs (which is a little old now) is that; major problem with PhantomJs as a report generator tool is that it does not produce paper perfect content. I struggled a lot but I couldn't generate paper aligned content in my HTML. Stuff like preventing a table from being cut off in middle is unavoidable.

Sorry Guys , can someone help me to run this JS in Phantom. Actually I am new to Phantom and I am sure I am missing some argument. Below I have mentioned my command , with this it is creating blank PDF file . Please suggest how I can modify it to show correct result .

phantomjs abc.js http://www.google.com vikas.pdf [60cm*60cm,A4,Letter]

Second question regarding this would be do I need to mention complete kibana dashboard URL in the URL argument ?

+1

+1

+1

+1

+1

+1

+1

+1

+1

+2

Elastic devs,

could you please confirm if this comment is the right workaround for this issue.

If yes, which file do we need to add this snippet in to support exporting to pdf's

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

Don't you think it wouldn't be better to allow exporting charts to images first - anyone can than implement whatever they feel is the correct approach. Maybe hotlink some of the images to their intranet homepage or pull them periodically using cron. I would argue against having complete "share pdf" functionality as higher priority task because it's one (potentially marginal) usecase that is very specific to some uses of kibana. Why is this P1 and #1366 is P3? #1366 IMO promotes reusability and collaboration by allowing mashups with existing tools. Also this brings in "unrelated" activities like "planing" or "sending email". What do you think?

+1

+1
For Kibana used in enterprise with a lot of security management, it is really excruciating to get a report bypassing a lot of authentication/validation/VPN/proxying. A builtin report generator is really good option.

+1

+1

+1
The customer where I'm currently working (a very big organization) just asked me exactly this: can I export a graph and it's data in a PDF document? Here reporting it's like the blood in the veins, so it would be nice to be able to tell them: "YES, we can" :+1:

This was just now posted in the elasticsearch Facebook group, very interesting and could be very useful

http://teknosrc.com/elastictab-elasticsearch-to-excel-report/

+1

@elvarb,

Thanks for sharing this but any idea why i cannot download overall records
. I mean I can only see 250 records in excel sheet, however i have more
than 7000 docs.Is there any setting for elastic tab which needs to modify
to get more records in excel ?

On Tue, Feb 9, 2016 at 6:58 PM, Maxim Mesilov [email protected]
wrote:

+1


Reply to this email directly or view it on GitHub
https://github.com/elastic/kibana/issues/509#issuecomment-181864075.

_Regards,_
_Vikas Gopal_

@vg15

Sorry, can't help you there, not used that solution yet myself.

@elvarb @vg15 This issue is related to exporting visualizations, if you're looking for individual document exporting, #1992 is the issue you want to track.

+1 for PDF reports. Would like to see graph + table data ala Splunk style reports.

+1

+1

+5. Please take care of the page breaks too. So that the graphs are not distributed in two pages while printing.

+1

I have tried using this: https://github.com/fzaninotto/screenshot-as-a-service
It uses the same PhantomJS approach and adds additional configuration options to bypass http basic auth etc. It seems to work otherwise, but Kibana (v4.4.1) reports an error: Courier Fetch Error: unhandled courier request error: unknown error. Any ideas?

Nevermind. This works well after updating PhantomJS to 2.1.1 :)

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

Elastic devs, now that reporting feature is already released , will that be utilized to bring pdf export to kibana ?

heya, we have released reporting as a plugin to kibana, you can find more info here: https://www.elastic.co/products/reporting.

@kimchy , reporting seems to be a paid plugin. Will the pdf export ever come to kibana core itself .

@biswajit86 no, there are no plans. The reporting infrastructure we built and the generation of PDF/images are part of xpack. Note, we do provide it as part of our cloud offering in our cheapest tier (Standard): https://www.elastic.co/cloud/as-a-service/subscriptions.

how to authenticate in kibana using phantomjjs and then take a screen-shot?

Hi,

After some tests, I managed to export a Kibana dashboard to PDF using wkhtmltopdf.

More information here: https://github.com/theMiddleBlue/From-Kibana-to-PDF

hope this can help ✌️

@vg15

Sorry Guys , can someone help me to run this JS in Phantom. Actually I am new to Phantom and I am sure I am missing some argument. Below I have mentioned my command , with this it is creating blank PDF file . Please suggest how I can modify it to show correct result .

phantomjs abc.js http://www.google.com vikas.pdf [60cm*60cm,A4,Letter]
Second question regarding this would be do I need to mention complete kibana dashboard URL in the URL argument ?

Try this:-
phantomjs abc.js https://www.google.com testing.pdf A4 1920px

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bhavyarm picture bhavyarm  ·  3Comments

ynux picture ynux  ·  3Comments

timroes picture timroes  ·  3Comments

MaartenUreel picture MaartenUreel  ·  3Comments

cafuego picture cafuego  ·  3Comments