Skip to main content

HTMLArea

Version: 12.0

HTML Area

The HtmlArea Page Element renders HTML content within a specified area of the PDF page. The tag supports HTML 4.0.1 and CSS 2.1 specification tags and properties with a few limitations (see below).

HtmlArea​

An HtmlArea has numerous constructors that allow inputting the HTML from a steam, text, URL, or a file path.

tip

If working with complex HTML documents, then consider using either DynamicPDF HTML Converter for .NET or DynamicPDF Converter for .NET

Example​

The following example demonstrates adding content from an HTML file into a PDF document's page region.

Document document = new Document();
Page page = new Page(PageSize.Letter);
document.Pages.Add(page);

float hgt = page.Dimensions.Height - page.Dimensions.TopMargin * 2;
float wdth = page.Dimensions.Width - page.Dimensions.LeftMargin * 2;

Uri filePath = new Uri("simple.html");
HtmlArea htmlArea = new HtmlArea(filePath, 0, 0, wdth, hgt);

page.Elements.Add(htmlArea);
document.Pages.Add(page);
document.Draw(outputPath);
Dim document As New Document()
Dim page As New Page(PageSize.Letter)
document.Pages.Add(page)

Dim hgt As Single = page.Dimensions.Height - page.Dimensions.TopMargin * 2
Dim wdth As Single = page.Dimensions.Width - page.Dimensions.LeftMargin * 2

Dim filePath As New Uri("simple.html")

Dim htmlArea As New HtmlArea(filePath, 0, 0, wdth, hgt)

page.Elements.Add(htmlArea)

document.Pages.Add(page)

document.Draw(outputPath)

[HtmlAreaExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/HtmlAreaExample.cs){#gitlink-id target=_blank}


[HtmlAreaExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/HtmlAreaExample.vb){#gitlink-id target=_blank}

HTML & CSS Support​

DynamicPDF Core Suite supports the following HTML tags and CSS properties.

HTML TagsCSS
a
address
blockquote
center
div
img
br
hr
h1
h2
h3
h4
h5
h6
p
pre
dd
dl
dt
li
ol
ul
table
b
i
q
u
em
tt
big
del
dfn
ins
kbd
sub
sup
var
abbr
cite
code
font
samp
span
small
s
strike
strong
input
textarea
label
button
fieldset
legend
select
acronym
background
color
text-decoration
letter-spacing
text-align
text-indent
text-transform
word spacing
font
border
margin
padding
height
min-height
max-height
width
min-width
max-width
line-height
position
clip
top
right
bottom
left
z-index
list-style
border-collapse
border-spacing
caption-side
empty-cells
table-layout
clear
display
float
visibility
page-break-after
page-break-before

Character Encoding​

The HTML passed to an HtmlArea uses the following character encodings.

  • The encoding specified in the HTML file header is used when the HTML source is an HTML file. If that is not present, the HTML meta charset is used.
  • The character encoding specified in the HTML Meta charset converts an HTML string.
  • UTF-8 is the default encoding used by the HTML Area when there is no meta charset or file encoding specified.

Limitations​

Supported tags and properties are based on HTML 4.0.1 and CSS 2.1 specifications. Refer to the Product Limitations documentation for a complete listing of limitations.