使用ITextHandler将XML转换成pdf时,发现转换出的pdf长度为0
本人正在做生成pdf的功能。
现在需要将一个xml文件转换成pdf。
我用了如下的参考代码
// step 1: creation of a document-object
Document document = new Document();
try
{
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter.GetInstance(document, new FileStream("Chap0703.pdf", FileMode.Create));
HtmlWriter.GetInstance(document,new FileStream("Chap0703.htm", FileMode.Create));
// step 3: we create a parser
ITextHandler h = new ITextHandler(document);
// step 4: we parse the document
h.Parse(@"E:\doc\111\Config.xml");
}
catch (Exception e)
{
Console.Error.WriteLine(e.StackTrace);
Console.Error.WriteLine(e.Message);
}
但问题是转换出来的pdf永远都是空的。为什么啊?