私はのコードを持っています:
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% には引き上げられません。
誰かが前にそれを見たことがありますか?ありがとう