-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin to provide PDF export of data #5491
Comments
I’d love to see this happen |
Why not render the graphs in PDF? The TCPDF PHP library already has a PieSector ( http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html#methodPieSector ) function to render a "Pie Piece". This would generate a vector graph which only need a few bytes in the PDF and can be freely scaled without getting blurry. I'm sure there's also some bargraph code somewhere ... if not, it's easy to create one. |
Started to work on this plugin. Will be have a beta version for testing soon. First we add in the admin interface a new tab: PDF Export Settings In the beta release we also want to have a dropdown where you can choose a template for the PDF report (own logo, etc.) Also we gave you the possibility to save the reports on you server in a specified directory. In the front we add a new tab like "goals" or "actions". You can add a new report and also see which reports exists for this idSite. This feature is usefull if you want to generate different reports for different user groups (e.g. management report or design/graphical report). Here you can choose start and end date and also if you want to have diagrams in the report. At the moment you can only download the PDF by clicking on a button. For PDF generation we use fpdf library, because we use this library before (over the API) and it was easily to install in the plugin. If you have some comments on the screens please let me know. More screens will follow until we release the beta version. |
Attachment: Admin screen (not complete yet) |
Attachment: Position of plugin entry for users |
Christian, thanks for updating us.
It sounds like you are making great progress. Let us know if you have questions, missing hooks in the code, etc. that would block your development. We're really looking forward to seeing this PDF export :) |
Hello, This plugin seems to be very interresting. I must developp a similary plugin which enables people to export data in PDF format. Could you please contact me by mail at: [email protected] |
Attachment: V 0.1 |
Feedback on V0.1 submitted by Christian. First of all, very good start :) Here is a review of the screens/UI and the code. UI/product feedback
Code feedback
Clarification on 'generating PDF' screen
I would recommend if possible you work on these features first without adding new ones, and we can try to have a beta version that we can integrate in core. After this we could work on other new features (sending reports by email, adding graphs, etc.). Thanks! |
(In [2312]) Refs #5491
|
Attachment: |
Attached the beta version for PDF export with the comments by Matt. Waiting for a new code review. Thank to Jeremy and Alex for the work done on this plugin to the beta status. |
In the submitted version, I wasn't able to generate a PDF with reports (list of reports didn't display). I'll still do a code review:
Let me know when you need a new code review, good progress, but some cleaning work left before we can integrate. Thanks! |
Attachment: Plugin + patch |
Code review Core patch
PDF plugin feedback User Interface
code review
you can write
use Piwik_Date::factory($this->date)->get('Y-m-d') which will handle all cases
Instead you can just do $this->getReport($idSite, .... ) which is the same
Please check all the code and make all is refactored (very important for maintenance)
should simply be
you could write something like
as said, I haven't tested functionnality yet as I'm waiting for patch. Good luck :) let me know if you need help |
new files: http://dl.free.fr/d98xMeThE Good work on the review, the code is now getting much better!! I hope we can reach a good working version soon. Generating pdf was not working for me (see attached pdf) but I still reviewed code and UIs Could you please attach a PDF with all reports that are possible to generate, and some data, so I can see how it looks? thanks Core Code review
write the more simple
makes code much more readable. i saw it in other codes like sendTemplate() and sendEmail() etc.
UI
Code review
Schemas To meet requirements from spec, here are some changes to make to schema. Some other templates/php changes will follow in some cases...
Finally, can you please remove all TCPDF files that are not directly used by Piwik? TCPDF is a great library but is very heavy. Can you please remove fonts, images, docs, etc. that are not used? (you can leave README and LICENSE please). We are trying hard not to increase the piwik package size and are careful about adding only useful files :) Looking forward to next release and hopefully I can generate a PDF next time :) |
Attachment: empty report with empty columns, and with a large logo (logo can be aligned on left and resized to fit on page) |
Actually, the PDF now load, but I had to install a Japanese font. Why? without this font (of course I didn't take a screenshot of the popup...) I couldn't display in acrobat reader, strange.. |
OK I was able to generate the PDF Looks good :)
Thanks! |
Attachment: |
Hi, You can find above our last version. Things which are not in the V0.4:
Our choices: logo upload, when there is a problem, just fails with a message on white page... it should instead be displayed with the standard error message on the screen (catch the exception in controller and set error message) #> For the moment it's quite difficult to manage the problem in Ajax so the error will be displayed in a white page. *Remove updateTemplate not used, or if time allows, makes the Template listing have a Edit button, like Goals, and reopen the Add template form pre-selected with the current template to edit... The edit should only update the name, and list of reports to display, just like the Add template screen. * #> We made a remove of updateTemplate. A later version could take care of this modification. Known issues: Due to Ajax request, sometimes the page does not refresh and block on "Loading Data". Just Click again on "Pdf export" in the top bar to refresh. |
(In [2663]) Refs #1485
|
Great plugin so far! My Ideas for discussion:
Footer-MetaData imaginable:
the usecase would be that someone compares two or more reports in printed versions. Without these meta-data you would be lost in loose sites. Are seo-metrics already included in the reports? e.g. google indexed sites, backlinks, pagerank, etc.? |
(In [2697]) Refs #5491
|
(In [2700]) Refs #5491 Fixing small ui issues |
(In [2706]) refs #5491 |
(In [2737]) Refs #5491
|
(In [2747]) Refs #5491 Anonymous users can't create/view/schedule PDF. |
(In [2749]) Refs #5491 Removing unused fonts from libs trying to keep release size at minimum |
I created a new report containing the info I need. Afterwards I press "download" in order to see the result an get 3 big messages: 1: 2: 3: 4: TCPDF ERROR: Can't open image file: /tmp/jpg_3S5g7f Each message has its own backtrace Is it a failure or is it related to my shared webspace settings? |
@matt: I tried your patch but there was no difference. Seems also that this randomly generated jpg_xxx-file does not exist. |
please add those 2 folders: libs/tcpdf/cache Afterwards pdf-files can be generated. Thanks! |
PDFReport Cache Folders are not in Piwik 1.0 installation package libs/tcpdf/cache please put those folders in package. greetings |
Re: last two comments. See #1656 This ticket is closed. |
(In [5415]) fixes #2706
|
(In [5582]) * fixes #2706, #2828, #2704, refs #1721, #2637, #2711, #2318, #71 : horizontal static graph implemented
|
(In [6478]) fixes #2708 refs #5491
|
(In [6849]) refs #3323 #3088 #2708 #71 #2318
|
Users need to share Piwik reports with colleagues, customers or externals. PDF is the standard way of exchanging rich data, with graphs, colors, consistent design.
For the first release of PDF export in Piwik, I think the following features would be important to have:
- Create the pdf: the PDF would not be customizable and would include all Piwik reports. The tables would be “all columns” tables, ie. they contain Visits, unique visitors, bounce rate, goal conversion rate, etc.
- Send & receive the PDF: the PDF would be downloadable via a click in the “User Settings” page. Also, a click on a link would send an email with the PDF attached to the given email addresses (easier for users to forward the emails to others rather than create a new email, attaching the PDF, etc.).
- Look and feel: the PDF reports would contain tables, that look similar to the tables in Piwik reports. For example, search engine icons, countries flags would be displayed. Each page would contain the title of the report, and as many rows as can fit on the page (maybe 20 rows per table?).
- Internationalization. The PDF reports would be localized in any of the 35+ languages.
Other features probably for later releases:
- Customize PDF: each user would be able to customize which reports make it in the PDF. Possibility to create several PDF reports, per website, or for a given website.
- Receive the PDF by email: using a new hook, see #1184, the PDF reports plugin could automatically generate and send PDF reports by email to each user that requested delivery. Users could customize the frequency (daily, weekly, monthly), and recipients (themselves and others) to send the PDF reports to.
- PDF contains sparklines
- Each Piwik widget/report can be exported in PDF (add a new export link below the table, next to CSV, XML, etc.).
Features currently not considered
- PDF contains graphs: bar, pie, evolution charts. Graphs export in PDF would be a major maintenance / time intensive task, as we would have to support a second graphing library, as OFC is flash based and can’t generate PNGs.
Here are some thoughts about the implementation. Please discuss before implementing, there might be better solutions.
Rendering a PDF could then be done by using following call:
```
module=API&
method=PDF.getReport&
report=$REPORT_ID&
idSite=$WEBSITE_ID&
token_auth=$TOKEN&
date=…&period=…
```
In V1, when customReports are not implemented, we would have a function PDF.getFullWebsiteReport which would return the PDF containing all reports for a given website.
There could also be a PDF.getWebsitesDashboard which would return a simple PDF containing main metrics for all websites visible to the user.
When called, the PDF API function would then:
- create and setup as default the PDF view.
- init the PDF: set colors, margins, titles, properties, generated time, etc.
- loop over all controllers, and methods that we wish to render.
- call the methods in each plugin’s controller which add data to the PDF. All methods would render the “all columns” data table (that shows visits, pages, time per visit, etc.) rather than just the simple table with only the visits column.
- render the final PDF and output it to the browser
Basic skeleton for the API method PDF.getReport
```
// set the default View to PDF Piwik_View::setDefaultView(new Piwik_View_PDF()); // define an array of Controllers/methods to call to render in this PDF, // eg. array( array( ‘Goals’, ‘index’), array(‘UserSettings’, ‘getBrowser’) ) // loop over all the array of methods to render // here we could add a new page, a pdf page title for the next report, etc. // for each controller method, call it, for example $content = Piwik_FrontController::getInstance()→fetchDispatch( ‘Goals’, ‘index’); // this will call the index() on Goals/Controller.php // which will, at the end, render the view eg. $view→getView()→render() // this will result in Piwik_View_PDF→render() call which adds the right data to the PDF file being built. // once all reports have been added to PDF, return PDF to the userfunction getReport($report, $idSite, $date, $period)
{
}
```
Currently in plugins Controllers, views are created with:
```
$view = new Piwik_View(‘Goals/templates/single_goal.tpl’);
```
The view object encapsulates the Smarty implementation. Variables are set to the view`
$view→name = $goalDefinition[‘name’];` and the view is rendered at the end of the controller method:`
echo $view→render();`
In order to add PDF export with minimal effort, PDF could be a new View class, implementing the iView interface.
Currently there is core/View.php which should probably be moved to core/View/Smarty.php
there is some generic code in render() which could probably be left in the new core/View.php parent object.
We could have Piwik_View_Smarty extends Piwik_View
then we would build Piwik_View_PDF extends Piwik_View
When building a PDF report, each controller’s method would be called, and the data would be added to the PDF report hold in this object. The report builder API would then output this aggregated PDF to the user.
Piwik_View_PDF could look at the template name passed in the view constructor, and based on this find out if it knows how to render this template. For example, calling the Goals.goalReport method (in plugins/Goals/Controller.php), the View is using the template Goals/templates/single_goal.tpl – if the view does know how to render this (given the variables are set properly like on the smarty template), then it can render it. If not, an error can be output. The PDF view would have logic that says: “Goals/templates/single_goal” must be rendered this way. Most templates are generic (datatable, etc.) so most of the work to render the reports would be done only once and automatically work for most reports.
The library might support automatic conversion of HTML into the PDF, but most likely this doesn’t work very well.
We will most likely have to write a basic PDF renderer for the datatable (equivalent of datatable.tpl).
By default, we can include all tables in the PDF. But reports are useful only if they contain the subset of information a given user is interested in. We could have a simple UI, listing all available reports, with a click and add to report feature. This would be internally linked to calls to controller methods. The layout could be saved as JSON in the reports table.
PDF reports do not apply on per report basis, like Bar graphs or Pie charts apply. There could be a link to generate a PDF report for the current website in the header.
Interested by this feature? Let us know in the comments.
The text was updated successfully, but these errors were encountered: