Hi,
Hello Ashutosh,
Thanks for contacting support.
You can use HtmlFragment class provided by DOM to add HTML at paragraph level, inside PDF document. Please check following code snippet that I have used to convert both HTML files into single page PDF document.
Document doc = new Document();
Page currpage = doc.Pages.Add();
HtmlFragment htmlFrag1 = new HtmlFragment(File.ReadAllText(dataDir + "input1.html"));
HtmlFragment htmlFrag2 = new HtmlFragment(File.ReadAllText(dataDir + "input2.html"));
currpage.Paragraphs.Add(htmlFrag1);
currpage.Paragraphs.Add(htmlFrag2);
doc.Save(dataDir + "SinglePagePdf_out.pdf");
For your reference, an output generated by above code is also attached. For more information, please visit “Add HTML string using DOM” article in API documentation. In case of any further assistance, please feel free to contact us.
Hi,
Hello Ashutosh,
Hi Ashutosh,
Thanks for writing back.
You can add HtmlFragment inside a table cell and set cell borders, in order to get the desired results. Please check following code snippet where I have added two different HtmlFragment(s) from different files with borders, inside a PDF.
Document doc = new Document();
Page currpage = doc.Pages.Add();
HtmlFragment htmlFrag1 = new HtmlFragment(File.ReadAllText(dataDir + “input1.html”));
HtmlFragment htmlFrag2 = new HtmlFragment(File.ReadAllText(dataDir + “input2.html”));
Table table = new Table();
table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;
table.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.5f);
table.DefaultCellPadding = new MarginInfo(2, 2, 2, 2);
Row row = table.Rows.Add();
Cell cell = row.Cells.Add();
cell.Paragraphs.Add(htmlFrag1);
row = table.Rows.Add();
cell = row.Cells.Add();
cell.Paragraphs.Add(htmlFrag2);
currpage.Paragraphs.Add(table);
doc.Save(dataDir + “HtmlFragWithBorder_out.pdf”);
For your reference, I have also attached an output generated by above code.
Best Regards,