HtmlRenderer.PdfSharp Message =“索引超出了数组的范围。”

时间:2017-09-22 14:30:04

标签: c# html pdf file-conversion

我尝试使用HtmlRenderer.PdfSharp将HTML转换为PDF。我的转换代码:

byte[] bytes;
var html = File.ReadAllText(htmlFilePath);

using (MemoryStream ms = new MemoryStream())
{
    var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A3);
    pdf.Save(ms);
    bytes = ms.ToArray();
}

File.WriteAllBytes(outputFilePath, bytes);

当我尝试从GeneratePdf方法生成PDF时,我得到一个例外:

  

索引超出了数组的范围。

堆栈追踪:

  

在   TheArtOfDev.HtmlRenderer.Core.Parse.RegexParserUtils.GetCssAtRules(字符串   样式表,Int32& startIdx)at   TheArtOfDev.HtmlRenderer.Core.Parse.CssParser.ParseMediaStyleBlocks(CssData   cssData,String stylesheet)at   TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox   box,HtmlContainerInt htmlContainer,CssData& cssData,Boolean&   cssDataChanged)at   TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox   box,HtmlContainerInt htmlContainer,CssData& cssData,Boolean&   cssDataChanged)at   TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox   box,HtmlContainerInt htmlContainer,CssData& cssData,Boolean&   cssDataChanged)at   TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.CascadeParseStyles(CssBox   box,HtmlContainerInt htmlContainer,CssData& cssData,Boolean&   cssDataChanged)at   TheArtOfDev.HtmlRenderer.Core.Parse.DomParser.GenerateCssTree(字符串   html,HtmlContainerInt htmlContainer,CssData& cssData)at   TheArtOfDev.HtmlRenderer.Core.HtmlContainerInt.SetHtml(字符串   htmlSource,CssData baseCssData)at   TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(字符串   html,PdfGenerateConfig config,CssData cssData,EventHandler 1 stylesheetLoad, EventHandler 1 imageLoad)in   d:\源\ github上\ HTML转译器\源\ HtmlRenderer.PdfSharp \ PdfGenerator.cs:线   122点   Plutora.Common.PhantomJS.PhantomRunner.ConvertHTMLtoPDF(字符串   pdfOutputLocation,String outputFilenamePrefix,String [] urls)at   Plutora.Common.PhantomJS.PhantomRunner.HtmlToPdf(字符串   pdfHtmlToPdfExePath,String pdfOutputLocation,String   outputFilenamePrefix,String [] urls,String runOptionsFormat,String   runOptionsOrientation)

我有本地HTML文件,内联CSS和绝对链接的CSS。

为什么我得到那个例外?怎么解决?

0 个答案:

没有答案