Toolbar customization


                        

Survey.Serializer.addProperty("survey", {
    name: "pdfOrientation",
    category: "PDF",
    categoryIndex: 10,
    default: "auto",
    choices: [
        "auto", "portrait", "landscape"
    ],
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    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
});
Survey.Serializer.addProperty("survey", {
    name: "pdfFormatWidth:number",
    category: "PDF",
    default: 210.0,
    dependsOn: "pdfFormatType",
    visibleIf: function (obj) {
        return obj.pdfFormatType === "custom";
    },
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfFormatHeight:number",
    category: "PDF",
    default: 297.0,
    dependsOn: "pdfFormatType",
    visibleIf: function (obj) {
        return obj.pdfFormatType === "custom";
    },
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
        name: "pdfFontSize:number",
        category: "PDF",
        default: SurveyPDF.DocOptions.FONT_SIZE,
        isSerializable: false
    });
Survey.Serializer.addProperty("survey", {
    name: "pdfFontName:string",
    category: "PDF",
    default: 'segoe',
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfMarginTop:number",
    category: "PDF",
    default: 10.0,
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfMarginBottom:number",
    category: "PDF",
    default: 10.0,
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfMarginLeft:number",
    category: "PDF",
    default: 10.0,
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfMarginRight:number",
    category: "PDF",
    default: 10.0,
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfHtmlRenderAs",
    category: "PDF",
    default: "auto",
    choices: [
        "auto", "standard", "image"
    ],
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfMatrixRenderAs",
    category: "PDF",
    default: "auto",
    choices: [
        "auto", "list"
    ],
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfCompress:boolean",
    category: "PDF",
    default: false,
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfMode",
    category: "PDF",
    default: "edit",
    choices: [
        "edit", "display"
    ],
    isSerializable: false
});
Survey.Serializer.addProperty("survey", {
    name: "pdfFileName:string",
    category: "PDF",
    default: 'survey_result.pdf',
    isSerializable: false
});
Survey.Serializer.addProperty("question", {
    name: "pdfIsPageBreak:boolean",
    category: "PDF",
    default: false
});

const options = { showLogicTab: true };            
                var creator = new SurveyCreator.SurveyCreator(options);
            
  const savePdfCallback = function() {
    const 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;
    }
    const surveyPDF = new SurveyPDF.SurveyPDF(creator.JSON, options);
    surveyPDF.data = creator.currentPlugin.model.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.toolbar.actions.push(new Survey.Action({
    id: "svd-save-pdf",
    title: "Save PDF",
    visible: new Survey.ComputedUpdater(() => creator.activeTab === "test"),
    enabled: true,
    action: savePdfCallback
}));                
                    creator.render("creatorElement");
                

                    
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Toolbar customization, Survey Creator Example</title>
    
<meta name="viewport" content="width=device-width" />
    <script src="https://unpkg.com/knockout@3.5.1/build/output/knockout-latest.js"></script>
    <script src="/DevBuilds/survey-core/survey.core.min.js"></script>
    <script src="/DevBuilds/survey-core/survey.i18n.min.js"></script>
    <script src="/DevBuilds/survey-knockout-ui/survey-knockout-ui.min.js"></script>
    <link href="/DevBuilds/survey-core/defaultV2.min.css" type="text/css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.10/ace.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.10/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
        <script src="/DevBuilds/survey-creator-core/survey-creator-core.min.js"></script>
        <link href="/DevBuilds/survey-creator-core/survey-creator-core.min.css" type="text/css" rel="stylesheet" />
        <script src="/DevBuilds/survey-creator-core/survey-creator-core.i18n.min.js"></script>
        <script src="/DevBuilds/survey-creator-knockout/survey-creator-knockout.min.js"></script>
        <style>
            :root {
                --tab-min-height: 600px;
            }
        </style>
    <link rel="stylesheet" href="./index.css">
    <script src="https://unpkg.com/jspdf@2.3.0/dist/jspdf.umd.min.js"></script>
    <script src="/DevBuilds/survey-pdf/survey.pdf.min.js"></script>

</head>
<body style="margin: 0">
    
<div id="surveyContainer">
            <div id="creatorElement" style="height: 100vh;"></div>
</div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>
Loading...
Sorry, we can't retrieve the data from server. Please comeback later.

Question Toolbar API

toolbarItems property: knockout observable array of toolbar items

Use toolbarItems for toolbar customizations. Only the given toolbar items will appear in the Toolbar

Question Toolbar Item properties

{
    id: string;
    visible: boolean | KnockoutObservable(boolean);
    title: string | KnockoutObservable(string);
    action: Function;
}
  • id - The required attribute. The unique toolbar item id.
  • visible - The required attribute. Controls visibility of the toolbar item.
  • title - The required attribute. Toolbar buuton title.
  • action - The required attribute. Function will be called on button click.

Why we use cookies.

This site uses cookies to make your browsing experience more convenient and personal. Cookies store useful information on your computer to help us improve the efficiency and relevance of our site for you. In some cases, they are essential to making the site work properly. By accessing this site, you consent to the use of cookies.

For more information, refer to DevSoft Baltic’ privacy policy and cookie policy.