Use Adorners
SurveyPDF adorners
You may use onRenderQuestion event to render custom elements in PDF document using internal SurveyPDF helper methods and objectsThe event is fired for every rendered question. Event accepts two parameters: instance of SurveyPDF and instance of AdornersOptions object
let surveyPDF = new SurveyPDF.SurveyPDF(json);
surveyPDF.onRenderQuestion.add(function (survey, options) {
if (options.question.name === "question_to_remove_from_pdf") {
options.bricks = [];
});
Bricks
AdornersOptions object contains bricks property with array of SurveyPDF internal objects which represents PDF document elements (texts, boxes, images, etc.). You may modify this array to perform custom rendering. If you leave this array without any changes then PDF will be rendered as by defaultQuestion
AdornersOptions's question property is SurveyJS question which is rendered nowController
AdornersOptions has controller property which is instance of DocController object. It is required parameter to many SurveyPDF internal methods
let surveyPDF = new SurveyPDF.SurveyPDF(json);
surveyPDF.onRenderQuestion.add(function (survey, options) {
if (options.question.name !== "filter questions like this") return;
//SurveyPDF bricks may be composite and contain many inside one
//call unfold() method to get plain array with all bricks inside one
var plainBricks = options.bricks[0].unfold();
var lastBrick = plainBricks[plainBricks.length - 1];
//SurveyPDF has SurveyHelper object with set of useful methods
//e.g. createPoint(rect: IRect, isLeft: boolean = true, isTop: boolean = false): IPoint
var point = SurveyPDF.SurveyHelper.createPoint(lastBrick);
return new Promise(function (resolve) {
SurveyPDF.SurveyHelper.createDescFlat(point, options.question,
options.controller, 'Some description').then(function (descBrick) {
options.bricks.push(descBrick);
resolve();
});
});
});
Point
AdornersOptions has point property (with xLeft, yTop properties) which represent point in PDF page after which you can render custom bricks below it. It is not recommended to draw above this point because you can overlap new bricks with previousRepository
AdornersOptions also has repository property which is instance of FlatRepository object. FlatRepository has create method which instantiate FlatQuestion and it subclasses, which can be used to generate bricks with default SurveyPDF render. You may modify this bricks to achieve desired custom view
let surveyPDF = new SurveyPDF.SurveyPDF(json);
surveyPDF.onRenderQuestion.add(function (survey, options) {
if (options.question.name !== "some_checkbox_question") return;
//create radiogroup flatQuestion to render checkbox as radigroup
var flatRadiogroup = options.repository.create(survey,
options.question, options.controller, "radiogroup");
return new Promise(function (resolve) {
flatRadiogroup.generateFlats(options.point).then(function(radioBricks) {
options.bricks = radioBricks;
resolve();
});
});
});