如何向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;
}
答案 0 :(得分:0)
我在html字符串的标头标记中添加了css参考:
<link rel='stylesheet' href='cssFilePath' type='text/css' media='all' />