htmlpdffontsitext

Font displayed differently in PDF and HTML


I am currently working on a web app to convert HTML to PDF (I am using iTextSharp to convert). I have noticed a problem with the fonts though. When I generate a font with 12px in HTML and in PDF, the display is different. The fonts in PDF looks bigger.

I'd like the HTML to be the closest possible to PDF, is there a way to have similar display? And why is the font so much bigger in PDF?


Solution

  • Have you tried .em and .pt instead of just .px

    p{font-size:1em}
    p{font-size:1pt}
    p{font-size:1px}
    

    Also try adding line-spacing. The iTextSharp:

    styles.LoadTagStyle("span", "size", "1em");
    styles.LoadTagStyle("span", "size", "1pt");
    styles.LoadTagStyle("span", "size", "1px");