![Create Survey Form from JSON Markup using C#](images/create-survey-form-from-json-markup-using-csharp.jpg#center)
Surveys play a vital role in market research for companies or organizations to grow their businesses. They use survey forms to collect customer feedback, user reviews, or opinions. Survey forms usually include multi-choice questions to mark user inputs. We can easily generate surveys, quizzes, and ready-to-print OMR answer sheets from JSON markup programmatically. JSON allows storing and transporting data that can be parsed and processed programmatically. In this article, we will learn how to create a survey form from JSON markup using C#.
The following topics shall be covered in this article:
- C# OMR API to Create Survey Form from JSON
- Create OMR Survey Form from JSON Markup
- Create PDF survey form from JSON
C# OMR API to Create Survey Form from JSON
For creating survey forms from JSON markup, we will be using the Aspose.OMR for .NET API. It allows designing, creating, and recognizing answer sheets, tests, MCQ papers, quizzes, feedback forms, surveys, and ballots.
Please either download the DLL of the API or install it using NuGet.
PM> Install-Package Aspose.OMR
Create OMR Survey Form from JSON Markup using C#
We can create a survey form from JSON markup by following the steps given below:
- Firstly, create an instance of the OmrEngine class.
- Next, call the GenerateJSONTemplate method with JSON markup file path as an argument.
- After that, get results as an object of the GenerationResult class.
- Finally, call the Save method to save template images and OMR template. It takes the path of the local disk folder and name of the template as arguments.
The following code example demonstrates how to create an OMR survey form template from JSON markup using C#.
// This code example demonstrates how to generate Survey image and OMR from JSON markup. | |
// Path to the JSON file with Template Markup | |
string markupPath = @"C:\Files\OMR\SimpleSurvey.json"; | |
// Initialize OMR engine | |
OmrEngine engine = new OmrEngine(); | |
// Generate Template | |
GenerationResult res = engine.GenerateJSONTemplate(markupPath); | |
// Save to the local disk | |
res.Save(@"C:\Files\OMR\", "SimpleSurvey"); |
![Create OMR Survey Form from JSON Markup using C#](images/Create-OMR-Survey-Form-from-JSON-Markup-724x1024.png#center)
Create OMR Survey Form from JSON Markup using C#
We have used the following JSON template markup in the code example mentioned above.
{ | |
"element_type": "template", | |
"children": [ | |
{ | |
"element_type": "page", | |
"children": [ | |
{ | |
"name": "Welcome to Sample Survey", | |
"element_type": "text", | |
"font_style": "bold", | |
"font_size": 16, | |
"align": "center" | |
}, | |
{ | |
"element_type": "emptyLine" | |
}, | |
{ | |
"element_type": "text", | |
"name": "February 25, 2022", | |
"font_style": "italic", | |
"align": "right" | |
}, | |
{ | |
"element_type": "emptyLine" | |
}, | |
{ | |
"name": "Section - I", | |
"element_type": "text", | |
"font_style": "bold", | |
"font_size": 14, | |
"align": "Left" | |
}, | |
{ | |
"font_family": "Segoe UI", | |
"font_style": "Regular", | |
"font_size": 12, | |
"align": "Left", | |
"answers_string": "(() Yes, indeed! () No", | |
"question_text": "Can Aspose.OMR process not only scans, but also photos?\r\n", | |
"element_type": "ChoiceBox" | |
}, | |
{ | |
"font_family": "Segoe UI", | |
"font_style": "Regular", | |
"font_size": 12, | |
"align": "Left", | |
"answers_string": "((Yes) Yes, indeed! (No) No", | |
"question_text": "Aspose.OMR works with any kind of OMR forms: tests, exams, questionnaires, surveys, etc.\r\n", | |
"element_type": "ChoiceBox" | |
}, | |
{ | |
"font_family": "Segoe UI", | |
"font_style": "Regular", | |
"font_size": 12, | |
"align": "Left", | |
"answers_string": "(() Very high quality () High quality\r\n() Average quality () Low quality", | |
"question_text": "How would you rate the quality of the product:\r\n", | |
"element_type": "ChoiceBox" | |
}, | |
{ | |
"font_family": "Segoe UI", | |
"font_style": "Regular", | |
"font_size": 12, | |
"align": "Left", | |
"answers_string": "(1) (2) (3) (4) (5) (6) (7) (8) (9)", | |
"question_text": "How likely is it that you would recommend our company to a friend or colleague?\r\n", | |
"element_type": "ChoiceBox" | |
}, | |
{ | |
"element_type": "emptyLine" | |
}, | |
{ | |
"children": [ | |
{ | |
"name": "Section - II", | |
"font_style": "Bold", | |
"font_size": 14, | |
"align": "Left", | |
"element_type": "Text" | |
}, | |
{ | |
"name": "main_container", | |
"children": [ | |
{ | |
"name": "main_block", | |
"children": [ | |
{ | |
"name": "product survey", | |
"children": [ | |
{ | |
"font_family": "Segoe UI", | |
"font_style": "Bold", | |
"font_size": 12, | |
"row_proportions": [ | |
60, | |
20, | |
10, | |
10 | |
], | |
"name": "How would you rate your total experience?", | |
"children": [ | |
{ | |
"name": "Score", | |
"header_type": "Amount", | |
"element_type": "ScoreHeader" | |
}, | |
{ | |
"name": "Yes", | |
"header_type": "Positive", | |
"element_type": "ScoreHeader" | |
}, | |
{ | |
"name": "No", | |
"header_type": "Negative", | |
"element_type": "ScoreHeader" | |
}, | |
{ | |
"Score": 5, | |
"element_type": "ScoreAnswer", | |
"name": "I am enjoy the product." | |
}, | |
{ | |
"Score": 10, | |
"element_type": "ScoreAnswer", | |
"name": "I will recommend it to my friends." | |
} | |
], | |
"element_type": "ScoreQuestion" | |
} | |
], | |
"score_group_type": "Table", | |
"element_type": "ScoreGroup" | |
} | |
], | |
"column": 1, | |
"element_type": "Block" | |
} | |
], | |
"columns_count": 1, | |
"element_type": "Container" | |
}, | |
{ | |
"element_type": "page", | |
"children": [ | |
{ | |
"name": "1-st", | |
"children": [ | |
{ | |
"name": "Process", | |
"children": [ | |
{ | |
"name": "Process", | |
"element_type": "writeIn" | |
} | |
], | |
"element_type": "block" | |
} | |
], | |
"element_type": "container" | |
} | |
] | |
} | |
], | |
"element_type": "Page" | |
} | |
] | |
} | |
] | |
} |
Create PDF Survey Form from JSON in C#
We can also save the generated survey form in a PDF document by following the steps mentioned above. However, we just need to call the SaveAsPdf(string folder, string name) method instead of the Save method in the last step.
// This code example demonstrates how to generate Survey OMR and Save as PDF from JSON markup. | |
// Path to the JSON file with Template Markup | |
string markupPath = @"C:\Files\OMR\SimpleSurvey.json"; | |
// Initialize OMR engine | |
OmrEngine engine = new OmrEngine(); | |
// Generate Template | |
GenerationResult res = engine.GenerateJSONTemplate(markupPath); | |
// Save to the local disk | |
res.SaveAsPdf(@"C:\Files\OMR\", "SimpleSurvey"); |
![Create Survey in PDF from JSON Markup using C#](images/Create-Survey-in-PDF-from-JSON-Markup.jpg#center)
Create PDF Survey Form from JSON in C#.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
Conclusion
In this article, we have learned how to create an OMR survey template from JSON markup and generate survey images. We have also seen how to save the generated survey in a PDF document programmatically. Besides, you can learn more about Aspose.OMR for .NET API using documentation. In case of any ambiguity, please feel free to contact us on our free support forum.