Skip to content

Commit 77a5969

Browse files
authored
feat(pdf): add configurable PDF compression level support (#34096)
1 parent fb9032c commit 77a5969

File tree

5 files changed

+8
-0
lines changed

5 files changed

+8
-0
lines changed

superset-frontend/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const DEFAULT_COMMON_BOOTSTRAP_DATA: CommonBootstrapData = {
170170
},
171171
d3_format: DEFAULT_D3_FORMAT,
172172
d3_time_format: DEFAULT_D3_TIME_FORMAT,
173+
pdf_compression_level: 'MEDIUM',
173174
};
174175

175176
export const DEFAULT_BOOTSTRAP_DATA: BootstrapData = {

superset-frontend/src/types/bootstrapTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export interface CommonBootstrapData {
163163
menu_data: MenuData;
164164
d3_format: Partial<FormatLocaleDefinition>;
165165
d3_time_format: Partial<TimeLocaleDefinition>;
166+
pdf_compression_level: 'NONE' | 'FAST' | 'MEDIUM' | 'SLOW';
166167
}
167168

168169
export interface BootstrapData {

superset-frontend/src/utils/downloadAsPdf.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import domToPdf from 'dom-to-pdf';
2121
import { kebabCase } from 'lodash';
2222
import { logging, t } from '@superset-ui/core';
2323
import { addWarningToast } from 'src/components/MessageToasts/actions';
24+
import getBootstrapData from 'src/utils/getBootstrapData';
25+
26+
const pdfCompressionLevel = getBootstrapData().common.pdf_compression_level;
2427

2528
/**
2629
* generate a consistent file stem from a description and date
@@ -58,6 +61,7 @@ export default function downloadAsPdf(
5861

5962
const options = {
6063
margin: 10,
64+
compression: pdfCompressionLevel,
6165
filename: `${generateFileStem(description)}.pdf`,
6266
image: { type: 'jpeg', quality: 1 },
6367
html2canvas: { scale: 2 },

superset/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
# "rel": "icon"
116116
# },
117117
FAVICONS = [{"href": "/static/assets/images/favicon.png"}]
118+
PDF_COMPRESSION_LEVEL: Literal["NONE", "FAST", "MEDIUM", "SLOW"] = "MEDIUM"
118119

119120

120121
def _try_json_readversion(filepath: str) -> str | None:

superset/views/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ def cached_common_bootstrap_data( # pylint: disable=unused-argument
488488
"EXTRA_CATEGORICAL_COLOR_SCHEMES"
489489
],
490490
"menu_data": menu_data(g.user),
491+
"pdf_compression_level": app.config["PDF_COMPRESSION_LEVEL"],
491492
}
492493

493494
bootstrap_data.update(app.config["COMMON_BOOTSTRAP_OVERRIDES_FUNC"](bootstrap_data))

0 commit comments

Comments
 (0)