带有 IronPDF 的表格布局 C#

在 C# 中,我使用 IronPDF 从 MYSQL 数据库中的数据创建 PDF。对于布局,我使用表格并使用单独的 CSS 文件对其进行设计。


当我在dreamweaver 或浏览器中尝试生成的HTML 和CSS 时,一切正常。当我在 IronPDF 中尝试时,生成的 PDF 中的表格边框不显示,并且表格中的 textalignment 是错误的。


有人知道这是怎么回事吗?IronPDF 中有什么东西会导致这个问题吗?


HTML:


<html>

<head>

<meta charset="utf-8">

    <link rel="stylesheet" type="text/css" href="test.css"/>

<title>test</title>

</head>


<body>

CSS:


#page {

width: 21cm 29.7cm;

margin: 27mm 16mm 27mm 16mm;

}



红颜莎娜
浏览 131回答 3
3回答

开满天机

更新:IronPDF 完全支持 CSS3 和表格。自 2021.9 版以来,它 100% 兼容 Chrome 2021https://www.nuget.org/packages/IronPdf/

ibeautiful

Ironpdf 仅接受内联 CSS,因此外部 CSS 不起作用。因此,请避免在 HTML 代码中使用类。还可以使用谷歌浏览器检查您的表格布局,因为 Ironpdf 会像谷歌浏览器一样渲染布局。你的代码应该像<!DOCTYPE html><html><body><h2>Basic HTML Table</h2><table style="width:100% ; border: 1px solid black ; border-collapse: collapse; ">&nbsp; <tr style=" border: 1px solid black ; border-collapse: collapse ">&nbsp; &nbsp; <th style=" border: 1px solid black ; border-collapse: collapse ">Firstname</th>&nbsp; &nbsp; <th style=" border: 1px solid black ; border-collapse: collapse ">Lastname</th>&nbsp;&nbsp; &nbsp; <th>Age</th>&nbsp; </tr>&nbsp; <tr style=" border: 1px solid black ; border-collapse: collapse ">&nbsp; &nbsp; <td style=" border: 1px solid black ; border-collapse: collapse ">Jill</td>&nbsp; &nbsp; <td style=" border: 1px solid black ; border-collapse: collapse ">Smith</td>&nbsp; &nbsp; <td style=" border: 1px solid black ; border-collapse: collapse ">50</td>&nbsp; </tr>&nbsp;&nbsp;</table></body></html>

忽然笑

这个问题很旧,但这可能对其他人有所帮助。正如之前的答案所指出的,Ironpdf 不支持来自文件的外部 css(尽管它确实支持来自 urls 的外部 css ..)因此,理想情况下,您在渲染器的同一个 html 文档中提供 css。这可以内联或在 html 头中完成,我更喜欢 html 头选项,如下所示<!DOCTYPE html><html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <style>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:100%;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border: 1px solid black;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-collapse: collapse;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tr, th, td{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border: 1px solid black;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border-collapse: collapse;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; </style>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; <h2>Basic HTML Table</h2>&nbsp; &nbsp; &nbsp; &nbsp; <table>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Firstname</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Lastname</th>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Age</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>Jill</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>Smith</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>50</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </table>&nbsp; &nbsp; </body></html>这会留下一个更干净的 html 文件并适用于当前版本的 ironpdf
打开App,查看更多内容
随时随地看视频慕课网APP