Does iText 7 pdfHtml Support CSS Grid Layout?

2.1k Views Asked by At

I can't seem to find a definitive answer on whether iText 7 supports CSS Grid layout. In my C# code, I'm simply using this line:

HtmlConverter.ConvertToPdf(new FileInfo(@"testgrid.html"), new FileInfo(@"out.pdf"));

Note: I'm using iText 7 v7.1.12

Let's say my html/css code looks something like this:

@page {
    size: A4;
    margin: 0;
}

.grid {
    display: grid;
    grid-template-rows: 1fr 1fr;
    grid-template-columns: 1fr 1fr;
}
<div class="grid">
    <div>
        <h3>A</h3>
    </div>
    <div>
        <h3>B</h3>
    </div>
    <div>
        <h3>C</h3>
    </div>
    <div>
        <h3>D</h3>
    </div>
</div>

If you run the html snippet above, you can see that the grid layout is displayed as expected, but when I run the C# code and open my out.pdf file, the grid styling is ignored and I see A, B, C, and D on separate lines.

enter image description here

Am I missing something, or does iText 7 HtmlConverter simply not support display: grid; in CSS?

1

There are 1 best solutions below

2
On BEST ANSWER

IronPDF and iText 7 HTML to PDF converters both do not support display: grid; or display: flex;.

If you want to use C# to convert HTML/CSS to PDF but it contains grid/flex, I think the only way you can do it is by using headless chrome:

var process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
String command = "/C \"\"C:/Program Files/Google/Chrome/Application/chrome.exe\"\" --headless --disable-gpu --print-to-pdf=C:/users/xxxxx/Documents/file.pdf --print-to-pdf-no-header C:/users/xxxxx/Documents/file.html";
System.Diagnostics.Process.Start("cmd.exe", command);