protected PdfPTable renderNonMCQQuestion(DataRow question, int DTQuestionNumber)
        {
            ///Renders all short and long questions indiscriminately
            //Gives back the Qno + statement table

            PdfPTable Returner = new PdfPTable(1);

            Returner.WidthPercentage = 100;
            //Returner.SetWidths(new float[] { .05f, .95f });

            PDFtester PDFfuncs = new PDFtester();

            Phrase ph_Numbering = new Phrase(DTQuestionNumber + ". ", boldquestionfont12);
            Phrase ph_Statement = new Phrase(question["Statement"].ToString(), questionfontXtractr);

            ph_Numbering.Add(ph_Statement);

            PdfPCell cell_Question = new PdfPCell(ph_Numbering);

            PdfPCell cell_Diagram = null;

            if (question["Diagram"].ToString() != "")
            {
                iTextSharp.text.Image diagramImage = iTextSharp.text.Image.GetInstance(Server.MapPath("Diagrams") + "/" + PDFfuncs.giveImageName(question["Diagram"].ToString()));
                diagramImage.ScaleToFit(new Rectangle(0f, 0f, 100f, 100f));

                PdfPTable DiagramHolder = new PdfPTable(1);
                DiagramHolder.WidthPercentage = 100;

                PdfPCell cell_ImgHolder = new PdfPCell(diagramImage);

                DiagramHolder.AddCell(PDFfuncs.removeBorders(cell_ImgHolder));
                DiagramHolder.AddCell(PDFfuncs.addViewFullSizeLink(question["Diagram"].ToString()));

                PdfPCell cell_dHolder = new PdfPCell(DiagramHolder);
                cell_dHolder.Colspan = 2;

                cell_Diagram = PDFfuncs.removeBorders(cell_dHolder);
            }
            else
            {
                cell_Diagram = new PdfPCell(); //if no diagram
            }
            Returner.AddCell(PDFfuncs.removeBorders(cell_Question));
            Returner.AddCell(PDFfuncs.removeBorders(cell_Diagram));

            return(Returner);
        }
        protected void generateQuestionsPDF()
        {
            DataTable WorkTable = getDataTableForQuestions(QuestionsType, CourseCode, IncludeCA);

            int RepetitionsCount = getRepetitionsCount(WorkTable);

            string strQtype = string.Empty;

            switch (QuestionsType)
            {
            case 1:
                strQtype = "Very short/MCQ Qestions [1 Mark]";
                break;

            case 2:
                strQtype = "Short Questions [2-2.5 Marks]";
                break;

            case 5:
                strQtype = "Short Questions [5 Marks]";
                break;

            case 10:
                strQtype = "Long Questions [10 Marks]";
                break;

            case 15:
                strQtype = "Long Questions [15 Marks]";
                break;

            default:
                break;
            }

            var    ExtractedQuestionsPDF = new Document(PageSize.A4, 30, 20, 50, 50);
            string SavePath = Server.MapPath("PDFs");

            PdfWriter.GetInstance(ExtractedQuestionsPDF, new FileStream(SavePath + "/Questions.pdf", FileMode.Create));

            ExtractedQuestionsPDF.Open();
            //addding header
            Paragraph header = new Paragraph(strQtype, TopHeader);

            header.Alignment = Element.ALIGN_CENTER;

            ExtractedQuestionsPDF.Add(header);
            //END//addding header

            if (CourseCode != "N")
            {
                Paragraph CCode = new Paragraph(CourseCode, TopHeader);
                CCode.Alignment = Element.ALIGN_CENTER;
                ExtractedQuestionsPDF.Add(CCode);
            }
            ///data set stats
            DataView view   = new DataView(WorkTable);
            int      qCount = view.ToTable(true, new string[] { "Statement" }).Rows.Count;
            //int qCount = WorkTable.Rows.Count;///200 questions found from 33 papers

            DataView dv = new DataView(WorkTable);

            int pCount = dv.ToTable(true, "PNR").Rows.Count;

            string QuestionsGrammarCorrector = qCount > 1 ? "questions" : "question";
            string PapersGrammarCorrector    = pCount > 1 ? "papers" : "paper";

            //int repcount = getRepetitionsCount(WorkTable);

            string RepsJoiner = string.Empty;

            if (RepetitionsCount > 1)
            {
                RepsJoiner = " with " + RepetitionsCount.ToString() + " repeated questions";
            }
            else if (RepetitionsCount == 1)
            {
                RepsJoiner = " with " + RepetitionsCount.ToString() + " repeated question";
            }

            Paragraph DataSetstats = new Paragraph("Showing " + qCount + " " + QuestionsGrammarCorrector + " from " + pCount + " " + PapersGrammarCorrector + RepsJoiner, Topsmall);

            DataSetstats.Alignment = Element.ALIGN_CENTER;

            ExtractedQuestionsPDF.Add(DataSetstats);
            //END/data set stats

            //// adding "Questions" header
            Paragraph QuestionsHeader = new Paragraph("Questions", TopHeader17);

            QuestionsHeader.Alignment = Element.ALIGN_CENTER;

            ExtractedQuestionsPDF.Add(new Paragraph("\n"));

            ExtractedQuestionsPDF.Add(QuestionsHeader);
            ExtractedQuestionsPDF.Add(new Paragraph("\n", small));
            //ExtractedQuestionsPDF.Add(new Paragraph("\n"));//spacemaker

            //END// adding "Questions" header

            /*
             * ////CA indicator
             * PdfPCell CAindicator = new PdfPCell(new Phrase("CA", Topsmall));
             * CAindicator.HorizontalAlignment = Element.ALIGN_CENTER;
             * //END//CA indicator
             */
            ////Real-time Question Table
            PdfPTable QuestionTable = new PdfPTable(4);//Numbering &Statement + Weightage + CA/MTE/ETE + RepetedSTAR

            QuestionTable.WidthPercentage = 100;
            QuestionTable.SetWidths(new float[] { .79f, .06f, .12f, .03f });

            PdfPCell cell_QuestionHolder = new PdfPCell();

            PDFtester PDFfuncs = new PDFtester();//getting custom PDF functions class

            int QuestionNumber = 1;

            for (int c = 0; c < qCount; c++)//rendering questions from Datatable to PDF///CAN BE OPTIMIZED MORE
            {
                DataRow question = WorkTable.Rows[c];

                QuestionTable.FlushContent();
                ////Adding question statement
                if (question["Option1"].ToString() == "")//is not MCQ
                {
                    cell_QuestionHolder = PDFfuncs.convertTableToCell(renderNonMCQQuestion(question, QuestionNumber++));
                }
                else
                {
                    cell_QuestionHolder = PDFfuncs.convertTableToCell(PDFfuncs.renderMCQQuestion(question, PDFfuncs.detectQuestionPattern(question), QuestionNumber++));
                }

                //QuestionTable.AddCell(cell_QuestionHolder);////PICKUP////
                //END//Adding question statement

                ////Adding Weightage
                //QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(new Phrase("[" + PDFfuncs.formatMarks(question["Weightage"].ToString()) + "]", questionfont))));////PICKUP////
                //END//Adding Weightage

                ////Adding QuestionPaper type
                Anchor PaperLinker = new Anchor(new Phrase(getQuestionSourcePaper(question["PNR"].ToString()), boldquestionfontLINK));
                //PaperLinker.Reference = "http://localhost:50876/ViewQuestionPaper.aspx?p=" + new QueryStringEncryption().encryptQueryString(question["PNR"].ToString());//for TEST environment only
                PaperLinker.Reference = "http://blackchair.manhardeep.com/ViewQuestionPaper.aspx?p=" + new QueryStringEncryption().encryptQueryString(question["PNR"].ToString());//for PRODUCTION environment only
                //QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(PaperLinker)));////PICKUP////
                //END//Adding QuestionPaper type

                ////Adding Repetitions thingy
                if (isRepeatedQuestion(question["QuestionID"].ToString()))
                {
                    if (!RepeatedQuestionOnceEntered.Contains(question["Statement"].ToString()))//Add to PDF only if not in pdf already
                    {
                        RepeatedQuestionOnceEntered.Add(question["Statement"].ToString());

                        iTextSharp.text.Image repIcon = iTextSharp.text.Image.GetInstance(Server.MapPath("Icons") + "/repIcon.png");

                        Chunk  chnk_RepeatedIcon       = new Chunk(repIcon, 0, 0, false);
                        Anchor repImage                = new Anchor(chnk_RepeatedIcon);
                        QueryStringEncryption Ecryptor = new QueryStringEncryption();
                        //repImage.Reference = "http://localhost:50876/RepetitionsShower.aspx?QuestionID=" + Ecryptor.encryptQueryString(question["QuestionID"].ToString()) + "&sl=" + giveRepetitionsHyperlinkURL(question["Statement"].ToString()) + "&p=" + Ecryptor.encryptQueryString(question["PNR"].ToString());
                        repImage.Reference = "http://blackchair.manhardeep.com/RepetitionsShower.aspx?QuestionID=" + Ecryptor.encryptQueryString(question["QuestionID"].ToString()) + "&sl=" + giveRepetitionsHyperlinkURL(question["Statement"].ToString()) + "&p=" + Ecryptor.encryptQueryString(question["PNR"].ToString());

                        PdfPCell cell_ImgREP = new PdfPCell(repImage);
                        cell_ImgREP.VerticalAlignment = Element.ALIGN_BOTTOM;
                        repIcon.ScaleAbsolute(30f, 30f);

                        QuestionTable.AddCell(cell_QuestionHolder);                                                                                                                ////PICKUP////
                        QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(new Phrase("[" + PDFfuncs.formatMarks(question["Weightage"].ToString()) + "]", questionfont)))); ////PICKUP////
                        QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(PaperLinker)));                                                                                  ////PICKUP////
                        QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(cell_ImgREP)));

                        ExtractedQuestionsPDF.Add(QuestionTable);
                    }
                    else
                    {
                        QuestionNumber--;
                        qCount++;
                        System.Diagnostics.Debug.WriteLine("in already in reps");
                        //QuestionTable.FlushContent();
                    }
                }
                else//if not repeated question
                {
                    QuestionTable.AddCell(cell_QuestionHolder);////PICKUP////
                    QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(new Phrase("[" + PDFfuncs.formatMarks(question["Weightage"].ToString()) + "]", questionfont)))); ////PICKUP////
                    QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell(PaperLinker)));                                                                                  ////PICKUP////
                    QuestionTable.AddCell(PDFfuncs.removeBorders(new PdfPCell()));
                    ExtractedQuestionsPDF.Add(QuestionTable);
                }
                //END//Adding Repetitions thingy

                ExtractedQuestionsPDF.Add(new Paragraph("\n"));
            }

            ExtractedQuestionsPDF.Close();
            PDFfuncs.AddPageNumber(Server.MapPath("PDFs") + "/Questions.pdf");
        }