12/14/2017
Batch PDF for Tableau Server or Tableau Public


In this post I will outline how to generate a batch of PDFs using Tableau Server (or Tableau Public) by passing parameters into the URL. Let's say you have a Tableau dashboard or report and you would like to filter it and generate a PDF for each value in the filter (or parameter). For example, one PDF generated per state, region, store number or salesperson. Here's the general outline.

Step 1: Build a Dashboard and save it to Tableau Server (or Tableau Public)

You might already have a dashboard in mind. Just make sure that you have filters or parameters set up for the values that you want to burst out. For example, if you want to create a PDF for each state then make sure state is set up as a filter.

In my example below, I tied State to a field called StateNum which is just 1 to 49.

Once you have the dashboard setup with your filter(s) or parameter(s), test out the PDF generation. You can do this by building a custom URL
The URL should be formatted like this:

http://[Name of TableauServer]/#/views/[Name of Workbook]/[Name of Worksheet].pdf

Here is a real example using my Tableau server.
http://tableau/#/views/Print2PDF/SampleDashboard.pdf

tableau is the name of my server
Print2PDF is the name of the Tableau workbook on the server
SampleDashboard is the name of the dashboard in my Tableau workbook that I want to generate.
Adding .pdf to the end of it generates it as a PDF document

We can filter the viz through that URL too (Ex. State, Region, Store ID, etc). In the URL below, it filters on a field called StateNum. The value of 6 equals Connecticut. Therefore, the PDF that is generated is for the State of Connecticut.
http://tableau/#/views/Print2PDF/SampleDashboard.pdf?StateNum=6

Tableau Public uses a similar structure.
https://public.tableau.com/views/[Workbook Name]/[Worksheet Name].pdf?:showVizHome=no

For Tableau Public, be sure to include the showVizHome=no. Here's an example of what the URL would look like for a Tableau Public viz using the Speaker Rating Dashboard from The Big Book of Dashboards.

https://public.tableau.com/views/CH3_BBOD_Individual_vs_Peers/SpeakerRatingsComparison.pdf?:showVizHome=no

We can adjust the parameter for the Speaker ID to generate a custom PDF for any of the speakers. For example, this URL would generate a PDF for speaker ID = 320.

https://public.tableau.com/views/CH3_BBOD_Individual_vs_Peers/SpeakerRatingsComparison.pdf?:showVizHome=no&Enter%20Speaker%20ID=320

Step 2: Set up an HTML page with some JavaScript.

You can do this on your local machine with a simple text editor. Notepad or Notepad++ will work fine.

Here's the general outline of this code.

1.) a variable named "links" is populated with all of the links that we want to generate into a batch report. Each one of these links will produce a unique PDF based on the filter.
2.) a function is created to download all of the URLs. The function loops through the list of links and downloads a PDF for each one. I included a line to parse the speaker ID out to name each file if allowed by the browser security (ex. Edge browser).
3.) the sample code in the body tag creates a button that fires off the function to download all of the PDFs when it's clicked.

Here's a sample button that will download 4 speaker rating PDFs from the sample viz above. Click it to give it a try.


Note – file naming does not work on all browsers due to browser security. I recommend using Edge for this since it will download them all at once and rename them for you.

Edge - will download and name the files based on the parsed name. Under advanced settings turn off "Ask me what to do with each download". This will allow you to download them all without having to click save for each file.
Chrome - will auto download, but the files will be named with the same name as the Tableau workbook along with a sequential number.
Firefox - will auto download, but the files will be named with the same name as the Tableau workbook along with a sequential number. Under Options, and Applications, change the Action for PDF to "Save As".
Internet Explorer - will open a tab for each document. Make sure to allow pop-ups for the website.

Also Note - You will need to adjust your browser settings to download PDFs automatically instead of previewing them in the browser. Each browser is different. Ex. for Chrome, Go to Settings -> search "content" and select Content Settings -> select PDF documents -> set "Download PDF files instead of automatically opening them in Chrome" to On.



Other Use Cases

Using .TWBX at the end of the URL will download a Tableau workbook. Therefore, inserting a list of different Tableau workbooks would trigger a download of all the Tableau workbooks in the "links" list. This could be used to allow a user to download all of the departments workbooks, or group of workbooks.

Using .PNG at the end of the URL will download PNG images of the dashboard. This could be used to download a gallery of images all at once for a set of dashboards.

Using .CSV at the end of the URL will download a CSV of the data for the dashboard. This could be used to download all of the underlying data used for a group of dashboards.


I hope you find this information useful. If you have any questions feel free to email me at Jeff@DataPlusScience.com

Jeffrey A. Shaffer

Follow on Twitter @HighVizAbility