Survey.StylesManager.applyTheme();
SurveyCreator.StylesManager.applyTheme();
Survey.Serializer.addProperties("survey",
[
{
name: "pdfOrientation",
category: "PDF",
default: "auto",
choices: ["auto", "portrait", "landscape"],
isSerializable: false
},
{
name: "pdfFormatType",
category: "PDF",
default: "default",
choices: ["custom", "default", "a0", "a1", "a2", "a3",
"a4", "a5", "a6", "a7", "a8", "a9", "a10",
"b0", "b1", "b2", "b3", "b4", "b5", "b6",
"b7", "b8", "b9", "b10", "c0", "c1", "c2",
"c3", "c4", "c5", "c6", "c7", "c8", "c9",
"c10", "dl", "letter", "government-letter",
"legal", "junior-legal", "ledger", "tabloid",
"credit-card"],
isSerializable: false
},
{
name: "pdfFormatWidth:number",
category: "PDF",
default: 210.0,
dependsOn: "pdfFormatType",
visibleIf: function (obj) {
return obj.pdfFormatType === "custom";
},
isSerializable: false
},
{
name: "pdfFormatHeight:number",
category: "PDF",
default: 297.0,
dependsOn: "pdfFormatType",
visibleIf: function (obj) {
return obj.pdfFormatType === "custom";
},
isSerializable: false
},
{
name: "pdfFontSize:number",
category: "PDF",
default: SurveyPDF.DocOptions.FONT_SIZE,
isSerializable: false
},
{
name: "pdfFontName:string",
category: "PDF",
default: 'segoe',
isSerializable: false
},
{
name: "pdfMarginTop:number",
category: "PDF",
default: 10.0,
isSerializable: false
},
{
name: "pdfMarginBottom:number",
category: "PDF",
default: 10.0,
isSerializable: false
},
{
name: "pdfMarginLeft:number",
category: "PDF",
default: 10.0,
isSerializable: false
},
{
name: "pdfMarginRight:number",
category: "PDF",
default: 10.0,
isSerializable: false
},
{
name: "pdfHtmlRenderAs",
category: "PDF",
default: "auto",
choices: ["auto", "standard", "image"],
isSerializable: false
},
{
name: "pdfMatrixRenderAs",
category: "PDF",
default: "auto",
choices: ["auto", "list"],
isSerializable: false
},
{
name: "pdfCompress:boolean",
category: "PDF",
default: false,
isSerializable: false
},
{
name: "pdfMode",
category: "PDF",
default: "edit",
choices: ["edit", "display"],
isSerializable: false
},
{
name: "pdfFileName:string",
category: "PDF",
default: 'survey_result.pdf',
isSerializable: false
}
]
);
Survey.Serializer.addProperty("question", {
name: "pdfIsPageBreak:boolean",
category: "PDF",
default: false
});
Survey.Serializer.findProperty("html", "renderAs").category = "PDF";
Survey.Serializer.findProperty("matrix", "renderAs").category = "PDF";
Survey.Serializer.findProperty("matrixdropdown", "renderAs").category = "PDF";
var creator = new SurveyCreator.SurveyCreator("surveyElement");
var savePdfCallback = function() {
var options = {
fontSize: creator.survey.pdfFontSize,
fontName: creator.survey.pdfFontName,
margins: {
left: creator.survey.pdfMarginLeft,
right: creator.survey.pdfMarginRight,
top: creator.survey.pdfMarginTop,
bot: creator.survey.pdfMarginBottom
},
htmlRenderAs: creator.survey.pdfHtmlRenderAs,
matrixRenderAs: creator.survey.pdfMatrixRenderAs,
compress: creator.survey.pdfCompress
};
if (creator.survey.pdfOrientation !== "auto") {
options.orientation = creator.survey.pdfOrientation;
}
if (creator.survey.pdfFormatType === "custom") {
options.format =
[creator.survey.pdfFormatWidth, creator.survey.pdfFormatHeight]
}
else if (creator.survey.pdfFormatType !== "default") {
options.format = creator.survey.pdfFormatType;
}
var surveyPDF = new SurveyPDF.SurveyPDF(creator.JSON, options);
surveyPDF.data = creator.surveyLiveTester.survey.data;
surveyPDF.mode = creator.survey.pdfMode;
surveyPDF.onRenderQuestion.add(function(_, options) {
options.bricks[0].isPageBreak = options.question.pdfIsPageBreak;
});
surveyPDF.save(creator.survey.pdfFileName);
};
creator.surveyLiveTester.toolbarItems.push({
id: "svd-save-pdf",
title: "Save PDF",
visible: true,
toolpit: "Save PDF",
component: "svd-button",
action: savePdfCallback
});