mirror of
https://github.com/apache/superset.git
synced 2026-04-07 10:31:50 +00:00
feat(pdf): add configurable PDF compression level support (#34096)
This commit is contained in:
committed by
GitHub
parent
fb9032c05c
commit
77a5969dc1
@@ -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 = {
|
||||
|
||||
@@ -163,6 +163,7 @@ export interface CommonBootstrapData {
|
||||
menu_data: MenuData;
|
||||
d3_format: Partial<FormatLocaleDefinition>;
|
||||
d3_time_format: Partial<TimeLocaleDefinition>;
|
||||
pdf_compression_level: 'NONE' | 'FAST' | 'MEDIUM' | 'SLOW';
|
||||
}
|
||||
|
||||
export interface BootstrapData {
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user