We are unable to print the PDF generated using HtmlFragment from html string.
We also unable to set the font size in the generated pdf.
Follow the below code for reference.
Document doc = new Document();
doc.PageInfo.Margin.Top = 0;
doc.PageInfo.Margin.Bottom = 0;
// Create the section in the Pdf object
Page sec1 = doc.Pages.Add();
// Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab1);
// Set with column widths of the table
tab1.ColumnWidths = “200 200”;
tab1.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;
// Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.None, 0.1F);
// Set table border using another customized BorderInfo object
tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.None, 1F);
int counter = 1;
Aspose.Pdf.Row row = new Aspose.Pdf.Row();
foreach (var item in lstEntity)
{
StringBuilder str = new StringBuilder();
str.Append("<p style="\font-family:verdana;">");
str.Append("<span style="\font-size:50%; “> " + item.text1 + " “);
str.Append(”
”);
”);
str.Append("<span style="\font-size:20%; “>” + item.text2 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text3 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text4 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text5 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text6 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text7 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text8 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text9 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text10 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text11 + “”);
str.Append("
");
");
str.Append("<span style="\font-size:20%; “>” + item.text12 + “”);
str.Append("");
HtmlFragment titel = new HtmlFragment(str.ToString());
Cell cell = new Cell();
cell.Paragraphs.Add(titel);
if (counter % 2 != 0)
{
row = tab1.Rows.Add();
row.FixedRowHeight = 270;
row.Cells.Add(cell);
}
else
{
row.Cells.Add(cell);
}
counter++;
}
dataDir = dataDir + “sample.pdf”;
// Save updated document containing table object
doc.Save(dataDir);