Hello Aspose,
I have multiple HTML codes in a table. I want to pass those HTML codes to create the PDF.
I want to pass those to a single HTMLFRAGMENT. (so far I have created seperate HTML fragments for each HTML codes. Now I want dynamically.)
Can we use a single HTMLfragment-->Paragraph-->Page for Multiple HTML codes?
Dim doc As Document = New Document()
Dim page As Page = doc.Pages.Add()
<>
Dim titel As HtmlFragment = New HtmlFragment('HTML value from FOR loop')
page.Paragraphs.Add(title)
<>
doc.Save("outputlpdf")
Can we create like this? if so, could you please provide clear coding to use this FOR loop.
--Thanks in Advance!!
Dinesh R
Hi Dinesh,
Thanks for your inquiry. Please check following code snippet for your requirement. Hopefully it will work.
List<string>
htmlstrings = new List<string>();<o:p></o:p>
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
HtmlFragment htmlFragment;
// Instantiate Document object
Document doc = new
Document();
// Add a page to pages collection of
PDF file
Page page = doc.Pages.Add();
foreach (String html in htmlstrings)
{
// Instantiate HtmlFragment with HTML contnets
htmlFragment = new HtmlFragment(html);
// Add HTML Fragment to paragraphs collection of page
page.Paragraphs.Add(htmlFragment);
}
// Save PDF file
doc.Save(myDir+"output_html.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
Hi Dinesh,
In addition to above reply. If you are generating PDF from html text only then it is recommend to use HtmlLoadOption() to create PDF as following instead adding HtmlFragment to PDF.
List<string>
htmlstrings = new List<string>();<o:p></o:p>
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
htmlstrings.Add("
Jill |
Smith |
50 |
Eve | Jackson | 94 |
");
String html1 = "";
foreach (String html in htmlstrings)
{
html1 =
html1+html;
}
HtmlLoadOptions loadOptions = new HtmlLoadOptions();
Document doc22 = new
Document(new
MemoryStream(System.Text.Encoding.UTF8.GetBytes(html1)), loadOptions);
doc22.Save(myDir + "outputhtml.pdf");
Best Regards,
Thanks Tilal Ahmad...!!!
It works..! :)
Thank you so much for your support.
Hi Dinesh,
Thanks for your feedback. It is good to know that you have managed to accomplish the requirements.
Please keep using our API and feel free to ask any question or concern, we will be more than happy to extend our support.
Best Regards,