Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# css样式表不适用于itextsharp_C#_Asp.net_Pdf_Itext - Fatal编程技术网

C# css样式表不适用于itextsharp

C# css样式表不适用于itextsharp,c#,asp.net,pdf,itext,C#,Asp.net,Pdf,Itext,我正在尝试从我拥有的html模板生成pdf。html模板有一个用于设置样式和格式的外部css文件。我能够生成pdf,但出于某种原因,它从不使用css表。为了得到这份工作,我这几天一直在绞尽脑汁。我唯一能找到的就是使用xmlworker。但我不知道如何在我的代码中使用它。有人能帮我解决这个问题吗 protected void Page_Load(object sender, EventArgs e) { // Create a Document object var docume

我正在尝试从我拥有的html模板生成pdf。html模板有一个用于设置样式和格式的外部css文件。我能够生成pdf,但出于某种原因,它从不使用css表。为了得到这份工作,我这几天一直在绞尽脑汁。我唯一能找到的就是使用xmlworker。但我不知道如何在我的代码中使用它。有人能帮我解决这个问题吗

protected void Page_Load(object sender, EventArgs e)
{

    // Create a Document object
    var document = new Document(PageSize.A4, 50, 50, 25, 25);

    // Create a new PdfWriter object, specifying the output stream
    System.IO.FileStream output = System.IO.File.Open(@"C:\test\" + "MyPdf.pdf", FileMode.Create);
    var writer = PdfWriter.GetInstance(document, output);


    // Open the Document for writing
    document.Open();

    // Read in the contents of the Receipt.htm file...
    string contents = File.ReadAllText(Server.MapPath("~/template/Receipt.html"));

    // Replace the placeholders with the user-specified text
    contents = contents.Replace("[JOBNUM]", "1234567890");


    // Step 4: Parse the HTML string into a collection of elements...
    var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);

    // Enumerate the elements, adding each one to the Document...
    foreach (var htmlElement in parsedHtmlElements)
        document.Add(htmlElement as IElement);

    // Close the Document - this saves the document contents to the output stream
    document.Close();
}

这个问题以前被问过很多次
HTMLWorker
不支持CSS样式表(该类已弃用)。只有xmlworker解释CSS文件。您能帮我在代码中使用xmlworker吗?不,我负责核心iText。XML Worker是由iText的其他人开发的。(您会注意到,我几乎从不回答XML工作者的问题。现在您也知道原因了。)请从这里开始