Absolute position when converting HTML to PDF using iTextSharp

I use iTextSharp to convert HTML to PDF and does not seem to work with absolutely positioned elements. For example, I have this HTML file:

<html>
<body>
    <p style="position: absolute; left: 10px; top: 100px; width: 50px;">Hello World</p>
</body>
</html>

The text is not set correctly in the resulting PDF file. Do you know if it is possible to have absolutely positioned elements when converting HTML to PDF? Any free solution (iTextSharp or another) that allows this would be greatly appreciated.

Here is the code I use to convert with iTextSharp:

class Program
{
    static void Main(string[] args)
    {
        Document document = new Document(PageSize.A4);
        using (Stream output = new FileStream("out.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
        using (Stream htmlStream = new FileStream("input.htm", FileMode.Open, FileAccess.Read, FileShare.Read))
        using (XmlTextReader reader = new XmlTextReader(htmlStream))
        {
            PdfWriter.GetInstance(document, output);
            HtmlParser.Parse(document, reader);
        }
        Process.Start(@"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe", "out.pdf");
    }
}        

EDIT:

, iTextSharp HTML PDF HTML-. Java- Flying Saucer, HTML-. IKVM, . , - . 31 HTML PDF . "" .

+3
3

- xhtmlrenderer. , , HTML .

JAVA, .NET IKVM.

+2

, Windows, PDFCreator COM HTML PDF ?

C:\Program Files\PDFCreator\COM\ , PDFCreator

0

ikvmc JARs , . iKVM, , Flying Saucer Java, :

`Cannot load AWT toolkit: ikvm.awt.NetToolkit, IKVM.AWT.WinForms, Version=0.40.0.1, Culture=neutral, PublicKeyToken=13235d27fcbfff58`

:

`ITextRenderer toRender = new ITextRenderer();`

Which seems to be the main object used by the Flying Saucer. Can you provide some source of how you used it?

0
source

Source: https://habr.com/ru/post/1705862/


All Articles