How to set margins in "em"

Hi,

While converting doc to epub I want to set paragraph margin in em unit. Below code is using for setting margin

DocumentBuilder builder = new DocumentBuilder(doc);
builder.ParagraphFormat.SpaceAfter = ConvertUtil.InchToPoint(1);

How to set margin in em instead of points ?

Hi Jeethu,

Thanks for your inquiry. “em” is relative to the font-size of the element e.g. 2em means 2 times the size of the current font. You can simulate the same behavior using the following code snippet:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Size = ConvertUtil.PixelToPoint(16); // Font size is 16px
builder.ParagraphFormat.SpaceAfter = ConvertUtil.PixelToPoint(2 * 16); // Spacing is 2em
builder.Writeln("These paragraphs have a calculated line-height of: 2x16px = 32px.");
builder.Writeln("These paragraphs have a calculated line-height of: 2x16px = 32px.");
builder.Writeln("These paragraphs have a calculated line-height of: 2x16px = 32px.");
doc.Save(MyDir + @"15.8.0.epub");

I hope, this helps.

Best regards,