【问题标题】:Adding CSS file to SelectPdf converter将 CSS 文件添加到 SelectPdf 转换器
【发布时间】:2019-02-27 07:46:11
【问题描述】:

如何向 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;
 }

【问题讨论】:

    标签: c# html-to-pdf converters selectpdf


    【解决方案1】:

    我在 html 字符串的 header 标签中添加了 css 引用:

    
        <link rel='stylesheet' href='cssFilePath' type='text/css' media='all' />
    
    

    【讨论】:

      猜你喜欢
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 2013-10-22
      • 2021-07-25
      相关资源
      最近更新 更多