v 1.8.79

Options in SurveyPDF Constructor

Basics

You can pass a set of options as a parameter into a SurveyPDF's constructor to predefine settings of the resulting PDF document.

var options = {
    // Specify option settings here.
    orientation: "p",
	fontSize: 14,
    //...
	}
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Online Example
Print to PDF - Options

The options are declared by the IDocOptions interface and are implemented by the DocOptions class.

List of Options

The following options are available (listed as they go in sources).

orientation?: 'p' | 'l';
format?: string | number[];
fontSize?: number;
fontName?: string;
base64Normal?: string;
base64Bold?: string;
useCustomFontInHtml?: boolean;
margins?: IMargin;
commercial?: boolean;
haveCommercialLicense?: boolean;
htmlRenderAs?: IHTMLRenderType;
matrixRenderAs?: 'auto' | 'list';
readonlyRenderAs?: 'auto' | 'text' | 'acroform';
textFieldRenderAs?: 'singleLine' | 'multiLine';
compress?: boolean;

List of Affected Preferences

Find more details about the available options in the below document sections that describe document preferences affected by corresponding options.

Page orientation

Use the orientation option to specify the page orientation within the document.

Possible values:

  • "p" - specifies the portrait orientation,
  • "l" - specifies the landscape orientation.

The default value is "p".

var options = {
    orientation: "l"
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Page format

Use the format option to specify the document's page size.

  • format
    format?: string | number[];

Possible values:

  • "a0" - "a10"
  • "b0" - "b10"
  • "c0" - "c10"
  • "dl"
  • "letter"
  • "government-letter"
  • "legal"
  • "junior-legal"
  • "ledger"
  • "tabloid"
  • "credit-card"

The default value is "a4".

var options = {
    format: "a3"
};
var survey = new SurveyPDF.SurveyPDF(json, options);

To use a custom format, set format to the required page size as a number array (in mm). Example: [210.0, 297.0] where 210.0 is the width and 297.0 is the height.

var options = {
    format: [210.0, 297.0]
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Note that setting the orientation option has priority over the format option. If you set format to [297.0, 210.0] (which defines landscape orientation) and explicitly set orientation to "p" (which specifies portrait orientation), document pages will have the portrait orientation.

See Example
Print to PDF

Font size

Use the fontSize option to specify the base font size (in points) for the PDF document's text elements.

The sizes of titles, descriptions, and text boxes will be calculated (scaled) proportionally based on the fontSize value.

var options = {
    fontSize: 14
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Font name

Use the fontName option to specify the font name or family for the PDF document's text elements.

The default document font is Segoe.
Two typefaces of this font (normal and bold) are by default embedded in a generated PDF document and are used to represent all survey texts within the document.

Specifying any other font instead of Segoe prevents embedding Segoe fonts into a PDF document and makes Segoe typefaces unavailable within the document.

Set the fontName option to the desired font's family name to switch from the default Segoe font to one of the standard 14 fonts or to a custom font (explicitly integrated into a document through the addFont() method).

Example: "Courier".

var options = {
    fontName: "Courier"
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Learn more: Change Fonts

Setting a custom normal font

Obsolete.

Use the addFont() method and the fontName option instead.

Learn more: Change Fonts

Settings a custom bold font

Obsolete.

Use the addFont() method and the fontName option instead.

Learn more: Change Fonts

Ability to use custom fonts in HTML questions

Obsolete.

  • useCustomFontInHtml
    useCustomFontInHtml?: boolean;
    Notes:
    Earlier was used together with base64Normal and base64Bold to specify whether custom fonts (loaded throught the base64Normal and base64Bold options) should apply to texts rendered within questions of the HTML type.

Now custom fonts loaded through the addFont() method are always taken into account when rendering texts within questions of the HTML type.

Page margins

Use the margins option to specify the margins for document pages.

var options = {
    margins: {
        top: 18,
        bot: 10,
        left: 12,
        right: 10
    }
};
var survey = new SurveyPDF.SurveyPDF(json, options);

See also: Custom Render - Header/Footer: Drawing area

Commercial license

Use the commercial or haveCommercialLicense option to specify whether you have a commercial license for the Survey PDF Export library.

Setting an option to true removes a non-commercial usage warning displayed on the top of the document.

var options = {
    commercial: true
};
var survey = new SurveyPDF.SurveyPDF(json, options);

or

var options = {
    haveCommercialLicense: true
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Important:
Setting any of these options to true without having a commercial license is illegal.

HTML question render mode

Use the htmlRenderAs option to specify how to render questions of the HTML type into the result PDF document.

Possible values are listed in IHTMLRenderType:

  • "auto"
    SurveyPDF automatically selects how to render each HTML question (as a standard text or as an image) depending upon the complexity of the processed HTML markup.

  • "standard"
    All HTML questions are rendered as standard selectable texts.

  • "image"
    All HTML questions are rendered as images (this might present the result of HTML markup more accurately but might increase the export time).

The default value is "auto".

var options = {
    htmlRenderAs: 'image'
};
var surveyPDF = new SurveyPDF.SurveyPDF(json, options);

When exporting a survey's HTML questions to a PDF document, it is a difficult task to map HTML elements to PDF document primitives. Therefore, in the default "auto" mode, SurveyPDF automatically chooses the more suitable from two render types - standard text or image.
If the markup of the processed HTML question is simple enough, it will be rendered to a PDF document as selectable text. This is more appropriate for long descriptive texts with a simple layout.
Complex HTML markup will be rendered as an image. For instance, this is suitable for greeting texts that might have an elaborate layout.

For each particular HTML question, you can override this general ("auto") behavior at the question level - by specifying a question's renderAs property (in a survey JSON definition). Set the property to "standard" or "image" as well (its default value is "auto").

var json = {
    elements: [
        {
            type: 'html',
            name: 'html_as_image',
            html: '<i>Cheeese!</i>',
            renderAs: 'image'
        }
    ]
};
var options = {
    // ...
};
var survey = new SurveyPDF.SurveyPDF(json, options);

See also
Export HTML questions to PDF

Matrix question render mode

Use the matrixRenderAs option to specify how to render questions of the matrix types into the result PDF document.

Possible values:

  • "auto"
    SurveyPDF automatically selects how to render each matrix question (as a table or as a list) depending upon the available space.
  • "list"
    All matrix questions are rendered as vertical lists.

The default value is "auto".

var options = {
    matrixRenderAs: 'list'
};
var surveyPDF = new SurveyPDF.SurveyPDF(json, options);

In "auto" mode, SurveyPDF initially tries to render each matrix question as a table. However, if there is no enough free space to accommodate a table, SurveyPDF renders a matrix as a narrow vertical list.

For each particular matrix question, you can override this general behavior at the question level - by specifying a question's renderAs property (in a survey JSON definition).

var json = {
    elements: [
        {    
            type: 'matrix',
            name: 'matrix_as_list',
            columns: [
                'Column 1'
            ],
            rows: [
                'Row 1'
            ],
            renderAs: 'list'
        }
    ]
}
var options = {
    // ...
};
var survey = new SurveyPDF.SurveyPDF(json, options);

Play with a live Plunker sample:
SurveyPDF - How to use the matrixRenderAs option and a question's renderAs property

SurveyPDF - Using matrixRenderAs option

Render mode of read-only questions

The readonlyRenderAs option allows you to fine tune the render of read-only questions in a PDF document being exported.

Possible values:

  • "auto"
    SurveyPDF automatically selects how to render composed elements of questions (in a custom manner as a selectable text surrounded by custom painted primitives such as borders or by using interactive AcroForm fields) depending upon the question's type.
  • "text"
    Plain text and custom painted primitives are used to render questions as not-interactive elements.
  • "acroform"
    Certain types of questions (Checkbox, Radiogroup, text fields in Text, Multiple Text, Matrix and Dropdown) are rendered with the help of the Acrobat Forms (AcroForms) technology as interactive form elements switched to their native read-only state.

The default value is "auto".

var options = {
    readonlyRenderAs: 'text'
};
var surveyPDF = new SurveyPDF.SurveyPDF(json, options);

For each particular question, you can override the default render behavior at the question level - by programmatically specifying a question's readonlyRenderAs custom property.

function saveSurveyToPdf(filename, surveyModel) {
    var surveyPDF = new SurveyPDF.SurveyPDF(json);
    surveyPDF.data = surveyModel.data;
    surveyPDF.getAllQuestions().forEach(function(question) {
        if (question.getType() === "file") {
            question.readOnly = true;
            question.readonlyRenderAs = "text";
        }
    });
    surveyPDF.save(filename);
}

See a live Plunker sample:
SurveyPDF - Export a file question with readonlyRenderAs set to text

Text input render mode in read-only questions

Use the textFieldRenderAs option to specify the manner in which single-line text fields display respondent answers (especially long ones) in the result PDF within questions of the following types:

The textFieldRenderAs option is only in effect for questions which are used in read-only mode due to one of the following settings:

  • a survey's mode property is set to 'display' (in a survey JSON definition),
  • a page's readOnly property is set to true,
  • a panel's readOnly property is set to true,
  • a question's readOnly property is set to true,
  • a SurveyPDF's mode property is set to 'display'.

You can identify a question's current state by using the isReadOnly property.

The textFieldRenderAs option allows you to better present long answers to open-ended questions in a PDF document.

Possible values:

  • "singleLine"
    SurveyPDF renders text input fields as typical single-line text boxes. The text that is too long and does not fit in a box' line is clipped. This mode is useful for short responses (5-7 words).
  • "multiLine"
    SurveyPDF renders text input fields in a manner similar to questions of the Comment type. Long text answers are displayed in multi-line format. Text boxes stretch vertically to accommodate the entire texts. This prevents text clipping.

The default value is "singleLine".

var options = {
    textFieldRenderAs: 'multiLine'
};
var surveyPDF = new SurveyPDF.SurveyPDF(json, options);
surveyPDF.mode = 'display'; 

You can play with a live Plunker sample:
SurveyPDF - How to use the textFieldRenderAs option

SurveyPDF - Using textFieldRenderAs option

Document compression

Use the compress option to specify whether to compress the generated PDF document. A compressed document does not support using custom fonts.

var options = {
    compress: true
};
var survey = new SurveyPDF.SurveyPDF(json, options);