Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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
Java 使用飞碟打印时,prolog中不允许来自DOM创建的文档的内容_Java_Html_Xml_Flying Saucer_Xhtmlrenderer - Fatal编程技术网

Java 使用飞碟打印时,prolog中不允许来自DOM创建的文档的内容

Java 使用飞碟打印时,prolog中不允许来自DOM创建的文档的内容,java,html,xml,flying-saucer,xhtmlrenderer,Java,Html,Xml,Flying Saucer,Xhtmlrenderer,我正试图用我的飞碟()打印一些文字。文档是使用DOM-API生成的,但打印开始时出现“prolog中不允许的内容”异常。这一例外的原因是什么 我的代码是: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder; documentBuilder = documentBuilderFactory.newDocumentB

我正试图用我的飞碟()打印一些文字。文档是使用DOM-API生成的,但打印开始时出现“prolog中不允许的内容”异常。这一例外的原因是什么

我的代码是:

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder;
documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element html = document.createElement("html");
document.appendChild(html);
Element body = document.createElement("body");
html.appendChild(body);
for (String paragraph : paragraphs) {
    Element paragraphTag = document.createElement("p");
    paragraphTag.setTextContent(paragraph);
    body.appendChild(paragraphTag);
}
XHTMLPanel panel = new XHTMLPanel();
panel.setDocument(document);

print(new XHTMLPrintable(panel));

print方法获取一个Printable并将其放入PrintJob。

XHTMLPrintable不能处理RAM中存在的文档。XHTMLPrintable尝试使用给定文档生成URL。然后将此“url”用作Graphics2Drender-fail的文档。
然后,我编写了自己的XHTMLPrintable,它采用文档而不是XHTMLPanel

我真的没有答案,因为看起来您正在做的任何事情都不会导致这种情况,但通常“prolog中不允许的内容”是由在标记之前插入的空格引起的。无法理解为什么会发生这种情况,因为您使用的是DOM。这也可能是由于出现了字节顺序标记,以及类似于print方法的东西没有处理它。尝试设置编码选项。@xcut如何设置BOM表或编码选项?我的代码从未将文档序列化为字符串或文件。编码选项真的重要吗?