Add HTML String using DOM in Python

Add HTML string in PDF DOM using Python

To add HTML string in Pdf document using Aspose.PDF Java for Python, simply invoke AddHtml module.


# Instantiate Document object
doc=self.Document()
page=doc.getPages().add()

title=self.HtmlFragment("<fontsize=10><b><i>Table</i></b></fontsize>")

margin=self.MarginInfo()
#margin.setBottom(10)
#margin.setTop(200)

# Set margin information
title.setMargin(margin)

# Add HTML Fragment to paragraphs collection of page
page.getParagraphs().add(title)

# Save PDF file
doc.save(self.dataDir + 'html.output.pdf')

print "HTML added successfully"

Download Running Code

Download Add HTML (Aspose.PDF) from any of the below mentioned social coding sites: