Apply a Theme to a PDF Form
This demo shows how predefined SurveyJS themes can be applied to both a web form and its PDF version to maintain a consistent appearance. SurveyJS themes are based on CSS variables and can be shared across all SurveyJS components. By default, the demo uses the Monochrome Light theme, which is optimized for printing. To try other themes or color palettes, open the Settings panel using the button in the bottom-right corner.
Predefined Themes
SurveyJS includes the following predefined themes:
- Default
- Contrast
- Borderless
- Flat
- Plain
- 3D
- Soft
- Monochrome
Each theme is available in Light and Dark variations, providing a total of 16 predefined theme options that can be applied to PDF forms.
SurveyJS themes also include "panelless" variations that remove question containers. These variations are not supported by PDF Generator.
In this and other PDF Generator demos, you can switch themes at runtime using the Themes panel. Theme changes are applied to the current web form immediately and used for the generated PDF when you click Download PDF or Preview PDF. If the Themes panel is not visible, open it using the button in the bottom-right corner of the Demo tab.
In PDF Generator, themes control colors and shadows only. Other visual properties, such as spacing, sizing, typography, and border radius, are defined by layouts.
Apply a Theme
A SurveyJS theme is a JSON object that defines a form's visual appearance. To apply a theme to a PDF form, import the theme object and pass it to the applyTheme method. The following code applies the Monochrome Light theme:
// Modular applications
import { MonochromeLight } from "survey-core/themes";
import { SurveyPDF } from "survey-pdf";
const surveyJson = { /* Survey JSON schema */ };
const surveyPDF = new SurveyPDF(surveyJson);
surveyPDF.applyTheme(MonochromeLight);
surveyPDF.save("my-pdf-form.pdf");
<!-- Classic script applications -->
<head>
<!-- ... -->
<script src="https://unpkg.com/survey-core/themes/monochrome-light.min.js"></script>
<!-- ... -->
</head>
<body>
<script>
const surveyPdf = new SurveyPDF.SurveyPDF({ /* ... */});
surveyPdf.applyLayout(SurveyTheme.MonochromeLight);
surveyPdf.save("my-monochrome-form.pdf");
</script>
</body>
Synchronize Themes Between Web and PDF Forms
If users can change themes at runtime, apply the survey's current theme to the PDF form before generating it:
function createSurveyPdfModel(surveyModel) {
const surveyPDF = new SurveyPDF(surveyJson, pdfOptions);
if (surveyModel) {
surveyPDF.data = surveyModel.data;
surveyPDF.locale = surveyModel.locale;
if (surveyModel.theme) {
surveyPDF.applyTheme(surveyModel.theme);
}
}
return surveyPDF;
}
For more information about themes and other appearance customization options, refer to the following help topic: