Skip to content
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

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

Open
d-bhatia opened this issue May 30, 2024 · 4 comments
Open

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

d-bhatia opened this issue May 30, 2024 · 4 comments
Labels
docs help wanted A user needs help, may be a mistake, a bug or a feature request

Comments

@d-bhatia
Copy link

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")

@jorwoods
Copy link
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.

@d-bhatia
Copy link
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

@jacalata
Copy link
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

@jacalata jacalata added the help wanted A user needs help, may be a mistake, a bug or a feature request label Jun 21, 2024
@jacalata
Copy link
Contributor

This has been implemented

@jacalata jacalata added the docs label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs help wanted A user needs help, may be a mistake, a bug or a feature request
Projects
None yet
Development

No branches or pull requests

3 participants