2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
The questionnaire can be created using PdfTextElement. Please find the code snippet and sample for the same. C#: //Create a PDF document PdfDocument doc = new PdfDocument(); //Add a page PdfPage newPage = doc.Pages.Add(); //Draw the question PdfLayoutResult layoutResult = AddQuestion(" Question 1 ", newPage, 0); //Draw the answer layoutResult = AddText("Answer 1", layoutResult.Page, layoutResult.Bounds.Bottom); //Draw the question layoutResult = AddQuestion("Question 2", layoutResult.Page, layoutResult.Bounds.Bottom); //Draw the answer layoutResult = AddText("Answer 2", layoutResult.Page, layoutResult.Bounds.Bottom); //Draw the question layoutResult = AddQuestion("Question 3", layoutResult.Page, layoutResult.Bounds.Bottom); //Read the texts from text file. StreamReader reader = new StreamReader(@"..\..\Data\Answer3.txt", System.Text.Encoding.ASCII); //Draw the answer layoutResult = AddText(reader.ReadToEnd(), layoutResult.Page, layoutResult.Bounds.Bottom); //Save the document. doc.Save(@"Output.pdf"); //Close the document. doc.Close(true); private PdfLayoutResult AddQuestion(string text, PdfPage page, float bottom) { PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); PdfBrush brush = PdfBrushes.Blue; float prevBottom = bottom + font.Height; //Rendering text PdfTextElement textElement = new PdfTextElement( text, font, brush); // Formatting layout PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat(); format.Layout = PdfLayoutType.Paginate; format.Break = PdfLayoutBreakType.FitPage; //Drawing string PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, prevBottom, page.GetClientSize().Width, 0), format); return result; } private PdfLayoutResult AddText(string text, PdfPage page, float bottom) { PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); PdfBrush brush = PdfBrushes.Black; float prevBottom = bottom + font.Height; //Rendering text PdfTextElement textElement = new PdfTextElement( text, font, brush); // Formatting layout PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat(); format.Layout = PdfLayoutType.Paginate; format.Break = PdfLayoutBreakType.FitPage; //Drawing string PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, prevBottom, page.GetClientSize().Width, 0), format); return result; }
Sample link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample163904622
|
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.