Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.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# ITextSharp在enddocument处引发NullReference异常_C#_Itextsharp - Fatal编程技术网

C# ITextSharp在enddocument处引发NullReference异常

C# ITextSharp在enddocument处引发NullReference异常,c#,itextsharp,C#,Itextsharp,我有一个代码: TextReader reader = new StringReader(html);// step 1: creation of a document-object var document = new Document(PageSize.A4, 30, 30, 30, 30); var resultPdf = new MemoryStream(); PdfWriter.GetInstance(document, resultPdf); var worker

我有一个代码:

  TextReader reader = new StringReader(html);// step 1: creation of a document-object
  var document = new Document(PageSize.A4, 30, 30, 30, 30);
  var resultPdf = new MemoryStream();
  PdfWriter.GetInstance(document, resultPdf);
  var worker = new HTMLWorker(document);
  document.Open();
  FontFactory.Register(FontFileName, "arial unicode ms");
  var st = new StyleSheet();
  st.LoadTagStyle("body", "encoding", "Identity-H");
  worker.Style = st;
  worker.StartDocument();
  worker.Parse(reader);
  worker.EndDocument();
  worker.Close();
  document.Close();
该代码在第行失败:

  worker.EndDocument();
除了:

  System.NullReferenceException: Object reference not set to an instance of an object.
  at iTextSharp.text.FontFactoryImp.GetFont(String fontname, String encoding, Boolean embedded, Single size, Int32 style, BaseColor color, Boolean cached)
  at iTextSharp.text.FontFactoryImp.GetFont(String fontname, String encoding, Boolean embedded, Single size, Int32 style, BaseColor color)
  at iTextSharp.text.html.simpleparser.FactoryProperties.GetFont(ChainedProperties props)
  at iTextSharp.text.html.simpleparser.FactoryProperties.CreateChunk(String text, ChainedProperties props)
  at iTextSharp.text.html.simpleparser.HTMLWorker.Text(String str)
  at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Flush()
  at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader)
我的html使用

  <div style="font-family: arial unicode ms">
  <div style="padding-left: 15px;">

不幸的是,它没有100%提高

以前有人看过吗?
谢谢

让我们猜一猜,您已经验证了
System.IO.File.Exists(pathToFont+“\\”+\u fontName)
,对吗
FontFactory.Register()
在无效字体路径上不会失败,但解析器稍后可能会在取消引用名称时失败。谢谢,是的,文件存在,该部分代码每天运行1000次,有时会在日志中失败,有时会成功。您使用的是什么版本的iTextSharp?您好,谢谢-我的版本是5.0.5.0,原因似乎是旧的简单多线程-只要我们更换了FontFactory.Register(FontFileName,“arial unicode ms”);使用if(FontFactory.isregisted(ARIAL_UNI_MS_FONT))。。。我们没有看到这些错误