Skip to content

PDF size from populated views too large - help wanted/bug #1382

Closed

Description

@d-bhatia

Some background:

Goal here is to download multiple filtered views as a pdf, ideally this should be done directly at a workbook level, but the filters don't work across the workbook.

Have browsed various suggested methods here and on the internet and the suggested approach was to filter each view seperately, download filtered view pdfs separately and merge them.

So approach is populate each view with applied filters, append them into a bytesIO stream and write to pdf.

Issue is this approach generates large pdfs from the views ~200KB resulting in an approx 1.8 MB pdf file (5 pages), alternatively doing so directly on the Tableau dashboard I can download multiple views (technically entire dashboard) in a smaller pdf ~ 917KB !

Code:

import pypdf as pdf
from io import BytesIO

pdflist=[]

for i in range(len(views)):
    server.views.populate_pdf(views[i],pdf_req_option)

writer = pdf.PdfWriter()

for j in range(len(pdflist)):
    
    stream = BytesIO(pdflist[j].pdf)
    writer.append(stream)

#---Compress and merge pdf
  
writer.write("filename.pdf")

Activity

  1. jorwoods commented on May 31, 2024

    @jorwoods
    Contributor

    In the upcoming 0.31 release you will be able to specify viz width and height when retrieving PDFs. #1348

    This should allow you to more precisely control your output size and give an apples to apples comparison.

  2. d-bhatia commented on May 31, 2024

    @d-bhatia
    Author

    Thanks, well print to pdf paper type used is letter in both cases, even tried with type unspecified, so not sure how width/height is going to help here

  3. jacalata commented on Jun 21, 2024

    @jacalata
    Contributor

    We will fix the server issue of not filtering a workbook and have it available this year.

    For a more immediate way to improve your exported pdfs, there are a lot of suggestions in this thread about compressing or optimizing pdfs including several python libraries.
    https://stackoverflow.com/questions/59614014/pypdf4-exported-pdf-file-size-too-big

  4. added
    help wantedA user needs help, may be a mistake, a bug or a feature request
    on Jun 21, 2024
  5. jacalata commented on Sep 20, 2024

    @jacalata
    Contributor

    This has been implemented

  6. github-actions commented on Jul 25, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. If this is still relevant, please comment to keep it open.

  7. jacalata commented on Aug 16, 2026

    @jacalata
    Contributor

    Closing -- this is supported. server.workbooks.populate_pdf(workbook_item, req_options) takes a PDFRequestOptions, which exposes vf(name, value) for view filters and parameter(name, value) for parameters. See tableauserverclient/server/endpoint/workbooks_endpoint.py:583 and tableauserverclient/server/request_options.py:531.

    Usage:

    opts = TSC.PDFRequestOptions().vf("Region", "West")
    server.workbooks.populate_pdf(workbook_item, opts)
    with open("filtered.pdf", "wb") as f:
        f.write(workbook_item.pdf)

    That gets a single server-rendered PDF with the filter applied across the whole workbook, which avoids the per-view download + client-side merge loop in the original report (the size difference was PDF concatenation overhead, not TSC).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docshelp wantedA user needs help, may be a mistake, a bug or a feature requeststale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions