Hello i am creating a simple math application in which we generate simple maths questions and then save these questions in PDF. We are using your pdf services for achieving this functionality. Now Questions are generated successfully in pdf but there are somple problems we are using your table system in this we want to add dynamically rows and columns in pdf according to questions and then show these different questions in a grid form in pdf here is my code thanks
public void GenerateTable()
{
using (PdfDocument document = new PdfDocument())
{
//Add a page
PdfPage page = document.Pages.Add();
//Acquire pages graphics
PdfGraphics graphics = page.Graphics;
PdfStringFormat CenterHeader = new PdfStringFormat(PdfTextAlignment.Center);
PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20);
PdfColor color = new PdfColor(240, 248, 255);
PdfSolidBrush brush = new PdfSolidBrush(color);
PdfPen borderPen = new PdfPen(PdfBrushes.LightGray);
borderPen.Width = 2;
//Default Style
PdfCellStyle defStyle = new PdfCellStyle();
defStyle.Font = font;
defStyle.BackgroundBrush = PdfBrushes.WhiteSmoke;
defStyle.BorderPen = borderPen;
defStyle.StringFormat = CenterHeader;
//Alternative Style
PdfCellStyle altStyle = new PdfCellStyle();
altStyle.Font = font;
altStyle.BackgroundBrush = brush;
altStyle.BorderPen = borderPen;
//Header Style
PdfCellStyle headerStyle = new PdfCellStyle(font, PdfBrushes.White, PdfPens.DarkBlue);
brush = new PdfSolidBrush(new PdfColor(0,0,0));
headerStyle.BackgroundBrush = brush;
headerStyle.StringFormat = CenterHeader;
//Declare a PdfLightTable
PdfLightTable pdfLightTable = new PdfLightTable();
PdfMargins margins = new PdfMargins();
PdfLightTableLayoutFormat pdflayout = new PdfLightTableLayoutFormat();
//Set the Data source as direct
pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect;
// pdfLightTable.Style.AlternateStyle = defStyle;
//Create columns
for(int i=0;i<4;i++)
{
pdfLightTable.Columns.Add(new PdfColumn("Questions"));
}
pdfLightTable.Style.CellPadding = 10;
pdfLightTable.Style.ShowHeader = false;
for (int i = 0; i < NumberOfQuestion; i++)
{
LeftOperant = LeftOperantList[i];
RightOperant = RightOperantList[i];
result = Calculation(LeftOperant, Operator, RightOperant);
QuestionsList.Add(" " + LeftOperant + "\n" + Operator + " " + RightOperant + "\n ------------ \n" + result + "\n ------------ \n");
// pdfLightTable.Rows.Add(new object[] { " "+LeftOperant+"\n"+ Operator+" "+ RightOperant + "\n ------------ \n" + result + "\n ------------ \n", "Noman","Waheed","Developers"});
}
foreach (var item in QuestionsList)
{
pdfLightTable.Rows.Add(new object[] { item,"","",""});
}
//Draw the PdfLightTable
// pdfLightTable.Draw(page, new PointF(50, 50));
pdfLightTable.Style.AlternateStyle = defStyle;
pdfLightTable.Style.DefaultStyle = defStyle;
pdfLightTable.Style.HeaderStyle = headerStyle;
pdfLightTable.Draw(page, PointF.Empty);
//pdfLightTable.Draw(page, 50, 50, 300, pdflayout);
//Save the document
MemoryStream stream = new MemoryStream();
document.Save(stream);
document.Close(true);
//Save the stream as a file in the device and invoke it for viewing
Xamarin.Forms.DependencyService.Get<ISave>().SaveAndView("PDFTable.pdf", "application / pdf", stream);
}