SoftwareDriven.SurveyJs.Pdf.Blazor
2.0.0
dotnet add package SoftwareDriven.SurveyJs.Pdf.Blazor --version 2.0.0
NuGet\Install-Package SoftwareDriven.SurveyJs.Pdf.Blazor -Version 2.0.0
<PackageReference Include="SoftwareDriven.SurveyJs.Pdf.Blazor" Version="2.0.0" />
<PackageVersion Include="SoftwareDriven.SurveyJs.Pdf.Blazor" Version="2.0.0" />
<PackageReference Include="SoftwareDriven.SurveyJs.Pdf.Blazor" />
paket add SoftwareDriven.SurveyJs.Pdf.Blazor --version 2.0.0
#r "nuget: SoftwareDriven.SurveyJs.Pdf.Blazor, 2.0.0"
#:package SoftwareDriven.SurveyJs.Pdf.Blazor@2.0.0
#addin nuget:?package=SoftwareDriven.SurveyJs.Pdf.Blazor&version=2.0.0
#tool nuget:?package=SoftwareDriven.SurveyJs.Pdf.Blazor&version=2.0.0
SoftwareDriven.SurveyJs.Pdf.Blazor
A Blazor WebAssembly wrapper for the SurveyJS PDF Generator — export a SurveyJS survey (and its answers) to PDF, or fill an existing PDF form with survey answers. The SurveyJS JavaScript is shipped inside the package as minified bundles, loaded on demand; no script tag or npm install is required in your app.
Targets .NET 10 (net10.0) and wraps SurveyJS PDF Generator 3.0.
Commercial license: The SurveyJS PDF Generator is not free for commercial use. Without a license key, exported PDFs carry an alert banner. Pass your key in as shown below.
Installation
dotnet add package SoftwareDriven.SurveyJs.Pdf.Blazor
Register the service (typically in Program.cs), optionally with your license
key:
using SoftwareDriven.SurveyJs.Pdf.Blazor;
builder.Services.AddSurveyJsPdf("YOUR-SURVEYJS-LICENSE-KEY");
// or without a key (adds a watermark):
builder.Services.AddSurveyJsPdf();
Usage
Inject SurveyPdf and export a survey. surveyJson and data accept a POCO, a
JsonElement, or a JSON string.
@inject SurveyPdf Pdf
<button @onclick="Download">Export PDF</button>
@code {
private readonly object surveyJson = new
{
elements = new object[]
{
new { type = "text", name = "firstName", title = "Your name" }
}
};
private async Task Download()
{
var answers = new { firstName = "Jane Doe" };
await Pdf.SaveAsync(surveyJson, answers, fileName: "survey.pdf");
}
}
To obtain the PDF without triggering a download — as bytes, a data URL, or a base64 string (e.g. to upload, embed, or transmit):
byte[] bytes = await Pdf.GetBytesAsync(surveyJson, answers);
string url = await Pdf.GetDataUrlAsync(surveyJson, answers); // data:application/pdf;base64,…
string base64 = await Pdf.GetBase64Async(surveyJson, answers);
Every generation method also accepts a locale (render the PDF in a language)
and a mode — SurveyPdfMode.Display renders answers as read-only text,
SurveyPdfMode.Edit as interactive form fields:
await Pdf.SaveAsync(surveyJson, answers, locale: "de", mode: SurveyPdfMode.Display);
The license key can also be set or changed at runtime:
await Pdf.SetLicenseKeyAsync("YOUR-SURVEYJS-LICENSE-KEY");
Appearance
Since SurveyJS 3.0 the PDF Generator is styled with the same design tokens as the
web form, so an export can carry the theme its on-screen counterpart uses. Pass a
SurveyPdfAppearance to any generation method:
await Pdf.SaveAsync(surveyJson, answers, appearance: new SurveyPdfAppearance
{
Theme = "ContrastLight", // colors and shadows
LayoutPreset = SurveyPdfLayout.Spacious, // spacing, sizing, typography
});
Themetakes the same values asSurveyHost.Theme— a built-in theme name ("DefaultLight","ContrastLight", …), or a theme POCO,JsonElement, or JSON string. Named themes are fetched lazily.LayoutPresetselects a built-in layout:SurveyPdfLayout.Compact(the SurveyJS default) orSurveyPdfLayout.Spacious. For full control, setLayoutto your own map of--sjs2-pdf-*CSS variables instead.Stylestakes a SurveyJSIDocStyleobject to override individual elements — survey and page titles, question containers, input fields, labels, panels and matrices:
appearance.Styles = new
{
surveyTitle = new { fontSize = 20, fontStyle = "bold" },
question = new { padding = 8, borderWidth = 1 },
};
Filling an existing PDF form
To produce an official form whose layout is fixed, map survey answers onto the interactive fields of an existing PDF instead of generating a document. Register the service:
builder.Services.AddSurveyJsPdfFormFiller("YOUR-SURVEYJS-LICENSE-KEY");
@inject SurveyPdfFormFiller Filler
@code {
private async Task Fill(byte[] template)
{
var fieldMap = new { firstName = "Vorname", city = "Ort" };
var answers = new { firstName = "Jane Doe", city = "Berlin" };
await Filler.SaveAsync(template, fieldMap, answers, fileName: "form.pdf");
}
}
fieldMap maps survey question names to the field ids in the PDF; open the
document in a PDF editor to find them. GetBytesAsync, GetDataUrlAsync and
GetBase64Async return the filled form instead of downloading it. The filler
bundles pdf-lib and ships as its own bundle, downloaded on first use.
API reference
SurveyPdf (scoped service, AddSurveyJsPdf()). Every generation method takes
(surveyJson, data?, options?, …, locale?, mode?, appearance?).
| Member | Description |
|---|---|
SaveAsync(surveyJson, data?, options?, fileName?, locale?, mode?, appearance?) |
Generates the PDF and triggers a browser download. |
GetBytesAsync(surveyJson, data?, options?, locale?, mode?, appearance?) |
Returns the PDF as byte[]. |
GetDataUrlAsync(surveyJson, data?, options?, locale?, mode?, appearance?) |
Returns the PDF as a data: URL string. |
GetBase64Async(surveyJson, data?, options?, locale?, mode?, appearance?) |
Returns the PDF as a base64 string (no prefix). |
SetLicenseKeyAsync(key) |
Sets/changes the SurveyJS commercial license key. |
options maps to SurveyPDF document options (e.g. new { fontSize = 12 }).
mode is SurveyPdfMode.Edit or SurveyPdfMode.Display.
SurveyPdfAppearance
| Member | Type | Description |
|---|---|---|
Theme |
object? |
Colors and shadows: a built-in theme name, or a theme POCO/JsonElement/JSON string. |
LayoutPreset |
SurveyPdfLayout? |
Compact (default) or Spacious. Ignored when Layout is set. |
Layout |
object? |
Custom layout variables (spacing, sizing, typography, radius). |
Styles |
object? |
SurveyJS IDocStyle overriding individual element styles. |
SurveyPdfFormFiller (scoped service, AddSurveyJsPdfFormFiller())
| Member | Description |
|---|---|
SaveAsync(pdfTemplate, fieldMap, data, fileName?) |
Fills the form and triggers a browser download. |
GetBytesAsync(pdfTemplate, fieldMap, data) |
Returns the filled form as byte[]. |
GetDataUrlAsync(pdfTemplate, fieldMap, data) |
Returns the filled form as a data: URL string. |
GetBase64Async(pdfTemplate, fieldMap, data) |
Returns the filled form as a base64 string (no prefix). |
SetLicenseKeyAsync(key) |
Sets/changes the SurveyJS commercial license key. |
License
Wrapper code: see repository. Bundled survey-pdf: commercial SurveyJS license
required — https://surveyjs.io/licensing. The form filler additionally bundles
pdf-lib (MIT).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 151 | 9/3/2026 |