Question T14195
Visible to All Users

Survey PDF dynamic height adjustment for type: "html" page only

created a year ago

HI Team,
We are rendering PDF contains two pages one page is for type: "multipletext" and the other page is for type: "html" both are separate pages only. For type: "multipletext" we need an height of 240 and for type: "html"` we required an height of600``` dynamically.
please help us to achieve this. Pease find the code below

Code
elements: [ { type: "multipletext", hideNumber: true, items, colCount: 1, defaultValue: formDataJson } ]  elements: [{                 type: "html",                 name: "html_as_image",                 html: wrapperDiv.innerHTML,                 renderAs: "image",             }             ]
Code
let pdfWidth = !!surveyModel && surveyModel.pdfWidth ? surveyModel.pdfWidth : 210 let pdfHeight = !!surveyModel && surveyModel.pdfHeight ? surveyModel.pdfHeight : 240; //This should be dynamic depends on the page type      let options: IDocOptions = {             fontSize: 9,             haveCommercialLicense: true,             margins: {                 left: 10,                 right: 10,                 top: 10,                 bot: 10             },             fontName: "calibri",             textFieldRenderAs: 'multiLine',             format: [pdfWidth, pdfHeight]         };

Please let us know for any clarifications.

Answers approved by surveyjs Support

created a year ago (modified a year ago)

Hello Santosh,
The Page format settings, which include a page width and height, are specified at the level of a PDF document.
Unfortunately, it is impossible to specify a different height for pages within the same PDF file. If you wish to export two questions on pages with different heights, I may suggest that you separate those questions, generate two different surveys and export them with a required PDF height.

Consider this demo:

JavaScript
function createSurveyPdfModel(surveyModel, filename) { const pageJSONs = json.pages.map((page) => { return { logoPosition: json.logoPosition, pages: [page] }; }); let counter = 0; pageJSONs.forEach((pageJson) => { let tempModel = new Model(pageJson); let questionType = tempModel.getAllQuestions()[0].getType(); let pdfWidth = !!surveyModel && surveyModel.pdfWidth ? surveyModel.pdfWidth : 210; let pdfHeight = !!surveyModel && surveyModel.pdfHeight ? surveyModel.pdfHeight : questionType === "html" ? 297 : 100; let options = { fontSize: 14, margins: { left: 10, right: 10, top: 10, bot: 10 }, format: [pdfWidth, pdfHeight] }; const surveyPDF = new SurveyPDF(pageJson, options); if (surveyModel) { debugger; surveyPDF.mergeData(surveyModel.data); surveyPDF.save(filename + counter + ".pdf"); counter++; } }); }

I hope it helps. Please let me know if you have any further questions.