Options in SurveyPDF Constructor
Basics
You can pass a set of options as a parameter into a SurveyPDF constructor to predefine settings for the resulting PDF file.
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;
applyImageFit?: boolean;
List of Affected Preferences
Find more details about the available options that describe document preferences affected by corresponding options in the sections below.
- Page orientation
- Page format
- Font size
- Font name
- Setting a custom normal font
- Setting a custom bold font
- Ability to use custom fonts in HTML questions
- Page margins
- Commercial license
- HTML question render mode
- Matrix question render mode
- Render mode of read-only questions
- Text input render mode in read-only questions
- Document compression
- Image rendering
Page orientation
Use the orientation option to specify the page orientation within the document.
- orientation
orientation?: 'p' | 'l';
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.
- fontSize
fontSize?: number;
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 file's text elements.
- fontName
fontName?: string;
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.
- base64Normal
base64Normal?: string;
Notes:
Earlier could be used together with base64Bold and useCustomFontInHtml.
Use the addFont() method and the fontName option instead.
Learn more: Change Fonts
Settings a custom bold font
Obsolete.
- base64Bold
base64Bold?: string;
Notes:
Earlier could be used together with base64Normal and useCustomFontInHtml.
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 thebase64Normal
andbase64Bold
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.
- margins
margins?: IMargin;
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 Generator library.
commercial
commercial?: boolean;
haveCommercialLicense
haveCommercialLicense?: boolean;
Setting an option to true removes a non-commercial usage warning displayed at 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 resulting PDF file.
- htmlRenderAs
htmlRenderAs?: IHTMLRenderType;
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 on 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 HTML question, you can override this general ("auto") behavior at the question level: specify a question's renderAs
property (in a survey JSON schema); also set the property to "standard" or "image" (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 matrix types questions into the resulting PDF file.
- matrixRenderAs
matrixRenderAs?: 'auto' | 'list';
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 matrix question, you can override this general behavior at the question level: specify the question's renderAs
property (in a survey JSON schema).
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
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.
- readonlyRenderAs
readonlyRenderAs?: 'auto' | 'text' | 'acroform';
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 question, you can override the default render behavior at the question level: programmatically specify 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 resulting PDF within questions of the following types:
- Text (QuestionTextModel),
- Multiple Text (QuestionMultipleTextModel),
- Matrix Dropdown (QuestionMatrixDropdownModel), if its cellType is set to 'text' (Cell type is set to Single Input in Survey Creator's Properties window),
- Matrix Dynamic (QuestionMatrixDynamicModel), if its cellType is set to 'text' (Cell type is set to Single Input in Survey Creator's Properties window).
The textFieldRenderAs option is only in effect for questions 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 schema),
- 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 present long answers to open-ended questions as a PDF file.
- textFieldRenderAs
textFieldRenderAs?: 'singleLine' | 'multiLine';
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
Document compression
Use the compress option to specify whether to compress the generated PDF document. A compressed document does not support using custom fonts.
- compress
compress?: boolean;
var options = {
compress: true
};
var survey = new SurveyPDF.SurveyPDF(json, options);
Image Rendering
Image questions have an imageFit property that specifies how images should fit into their containers. If exported images should apply this property, enable the applyImageFit
option. Please note that with this option, the quality of images may be lower because they pass through several conversions.
var options = {
applyImageFit: true
};
var survey = new SurveyPDF.SurveyPDF(json, options);
If applyImageFit
is disabled, exported images fill the entire container and do not preserve their aspect ratio, but their quality remains the same because they are exported as is.