U M A M A H E S H U M A M A H E S H - 1 year ago 361
CSS Question

iTextSharp PDF Base font size with XMLWorker

How can I set my PDF body font size "6.6pt" using XMLWorker?

I have achieved using HTMLWorker as like below,

var style = new StyleSheet();
style.LoadTagStyle("body", "size", "6.6pt");
HTMLWorker htmlWorker = new HTMLWorker(pdfDoc);

But how can I do this with XMLWorker?

Answer Source

This snippet of code:

var style = new StyleSheet();
style.LoadTagStyle("body", "size", "6.6pt");

was a poor version of applying CSS to the HTML you were parsing.

When using XML Worker, you can use real CSS.

Go the official web site and take a closer look at the examples, where we have CSS such as:

<table style="font-size:10pt">

Html: table10.html; Java: ParseHtmlTable10.java; PDF: html_table_10.pdf

Or CSS such as:

p           { font-size: 11px; font-family: "verdana", tahoma, arial, sans-serif; color: #040404; background-color: #FFFFEE; margin-top: 5px; margin-bottom: 8px; margin-left: 10px; }
h1          { font-size: 17px; color: #FFA500; margin-bottom: 10px; background-color: #0000EE; padding-top:6px; padding-bottom:7px; padding-left:10px; }    
h2          { font-size: 15px; color: #0055AA; margin-bottom: 10px; margin-top: 16px;  background-color:#FFCC66; padding-top:0px; padding-bottom:2px; padding-left:10px; }
h3          { font-size: 15px; color: #660000; margin-bottom: 8px;  margin-top: 15px; }
h4          { font-size: 12px; color: black; margin-bottom: 8px;  margin-top: 15px; margin-left: 8px; font-style: normal; }
code        { font-size: 12px; margin-left: 16px; padding-left:16px} 

HTML: paragj.html; Java: ParseHtmlTable6.java; PDF: html_table_6.pdf

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download