我有一个代码:
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%提高。
以前有人见过吗? 感谢