- How to add page numbers to your PDF
- Add text field to PDF
- Append multiple PDF documents
- Bulleted list from XML and XSL
- Merge PDF
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Convert TXT to PDF
- Convert XHTML to PDF
- Create PDF in C# - Tall Components - Check out our PDF code samples
- Text formatting
- Generate PDF form from XML
- Generate PDF with local images from XML with Xamarin.iOS
- XhtmlParagraph and TrueType fonts
- Add footer with left and right aligned text on same line
- Read and write meta data from PDF
- Stitch PDF documents
- Use multiple licenses
- What is the resulting fontsize in PDF rich text used in SimpleXhtmlShape
XhtmlParagraph and TrueType fonts
The following code converts XHTML to PDF using the XhtmlParagraph
. The HTML specfies Georgia as the font to use using an inline style attribute. The FontPath
property of ConversionSettings
instructs XhtmlParagraph
to use the fonts inside this folder.
Document document = new Document();
Section section = document.Sections.Add();
XhtmlParagraph xhtml = new XhtmlParagraph();
section.Paragraphs.Add(xhtml);
xhtml.Text = File.ReadAllText(@"in.html");
xhtml.Settings = new ConversionSettings { FontPath = @"d:\fonts" };
using (FileStream file = new FileStream("out.pdf", FileMode.Create))
{
document.Write(file);
}
Document in.html looks as follows:
<html>
<body>
<p style="font-family: Georgia">Hello world</p>
</body>
</html>