c# - 将 CSS 文件添加到 SelectPdf 转换器
问题描述
如何向 SelectPdf 转换器添加/引入 CSS 文件?
我使用SelectPdf库将 HTML 字符串转换为 PDF 文件。
我的 CSS 文件在cssFilePath
public byte[] Create(string htmlString)
{
string cssFilePath = Path.Combine(Directory.GetCurrentDirectory(), "assets", "PruefReportDataTableFormat.css");
string pdf_page_size = "A4";
PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true);
string pdf_orientation = "Portrait";
PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true);
int webPageWidth = 1024;
int webPageHeight = 0;
HtmlToPdf converter = new HtmlToPdf();
converter.Options.PdfPageSize = pageSize;
converter.Options.PdfPageOrientation = pdfOrientation;
converter.Options.WebPageWidth = webPageWidth;
converter.Options.WebPageHeight = webPageHeight;
PdfDocument doc = converter.ConvertHtmlString(htmlString);
byte[] result = doc.Save();
doc.Close();
return result;
}
解决方案
我在 html 字符串的 header 标记中添加了 css 引用:
<link rel='stylesheet' href='cssFilePath' type='text/css' media='all' />
推荐阅读
- gcc - set_c0_status() 函数在哪里定义?
- mongodb - 聚合组多个结果
- amazon-ec2 - AMAZON EC2:我的主机拒绝 VNC 连接(ubuntu)
- mysql - 在MYSQL中选择未来日期的最早日期
- javascript - 将右侧列拆分为 2 行,bootstrap,html,css
- r - 在字符串中查找模式并替换检测到的字符串稍作修改
- php - PayPal Pro/Express Omnipay Gateway - 信用卡标题无效
- python - 无法使用 pytorch 插入帧
- sql-server - 从查询中删除列
- html - 由于 ngModel,角度检查功能被忽略