diff --git a/superset-frontend/src/constants.ts b/superset-frontend/src/constants.ts index faf3012906b..4d8d4590fed 100644 --- a/superset-frontend/src/constants.ts +++ b/superset-frontend/src/constants.ts @@ -170,6 +170,7 @@ export const DEFAULT_COMMON_BOOTSTRAP_DATA: CommonBootstrapData = { }, d3_format: DEFAULT_D3_FORMAT, d3_time_format: DEFAULT_D3_TIME_FORMAT, + pdf_compression_level: 'MEDIUM', }; export const DEFAULT_BOOTSTRAP_DATA: BootstrapData = { diff --git a/superset-frontend/src/types/bootstrapTypes.ts b/superset-frontend/src/types/bootstrapTypes.ts index 1d8357a56ec..54af340cb74 100644 --- a/superset-frontend/src/types/bootstrapTypes.ts +++ b/superset-frontend/src/types/bootstrapTypes.ts @@ -163,6 +163,7 @@ export interface CommonBootstrapData { menu_data: MenuData; d3_format: Partial; d3_time_format: Partial; + pdf_compression_level: 'NONE' | 'FAST' | 'MEDIUM' | 'SLOW'; } export interface BootstrapData { diff --git a/superset-frontend/src/utils/downloadAsPdf.ts b/superset-frontend/src/utils/downloadAsPdf.ts index bb769d1eb11..c9c012a4a87 100644 --- a/superset-frontend/src/utils/downloadAsPdf.ts +++ b/superset-frontend/src/utils/downloadAsPdf.ts @@ -21,6 +21,9 @@ import domToPdf from 'dom-to-pdf'; import { kebabCase } from 'lodash'; import { logging, t } from '@superset-ui/core'; import { addWarningToast } from 'src/components/MessageToasts/actions'; +import getBootstrapData from 'src/utils/getBootstrapData'; + +const pdfCompressionLevel = getBootstrapData().common.pdf_compression_level; /** * generate a consistent file stem from a description and date @@ -58,6 +61,7 @@ export default function downloadAsPdf( const options = { margin: 10, + compression: pdfCompressionLevel, filename: `${generateFileStem(description)}.pdf`, image: { type: 'jpeg', quality: 1 }, html2canvas: { scale: 2 }, diff --git a/superset/config.py b/superset/config.py index 662e79576e1..f707642e4a1 100644 --- a/superset/config.py +++ b/superset/config.py @@ -115,6 +115,7 @@ PACKAGE_JSON_FILE = str(files("superset") / "static/assets/package.json") # "rel": "icon" # }, FAVICONS = [{"href": "/static/assets/images/favicon.png"}] +PDF_COMPRESSION_LEVEL: Literal["NONE", "FAST", "MEDIUM", "SLOW"] = "MEDIUM" def _try_json_readversion(filepath: str) -> str | None: diff --git a/superset/views/base.py b/superset/views/base.py index b0ad2c2e641..cb9676c6328 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -488,6 +488,7 @@ def cached_common_bootstrap_data( # pylint: disable=unused-argument "EXTRA_CATEGORICAL_COLOR_SCHEMES" ], "menu_data": menu_data(g.user), + "pdf_compression_level": app.config["PDF_COMPRESSION_LEVEL"], } bootstrap_data.update(app.config["COMMON_BOOTSTRAP_OVERRIDES_FUNC"](bootstrap_data))