xpage のコンテンツから PDF を作成しようとしています。私は、9 #102 のノートで Paul Calhoun が使用した形式に従っています。ビュー用の PDF を作成することはできますが、ドキュメント用の PDF の作成に問題があります。エラーが Paul のコードにあるとは思わないので、ここには含めませんが、必要に応じて含めることができます。
表示する XML を生成するには、Java のドキュメント クラスの generateXML() メソッドを使用します。バックエンド ドキュメントへのハンドルを取得し、XML を返します。XML は整形式のように見えます。最上位のタブは<document>
です。この XML を、Apache FOP を使用しているトランスフォーマーに渡します。私のコードはすべて xAgent の beforeRenderResponse に含まれています。
私が使用している XSL スタイルシートは、概念実証を機能させるためだけに簡素化されたバージョンです。問題はこのコードにある可能性が高いため、これを含めます。私は XSL の初心者です。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<xsl:output
method="xml"
version="1.0"
omit-xml-declaration="no"
indent="yes" />
<xsl:param
name="versionParam"
select="'1.0'" />
<xsl:template match="document">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
master-name="outpage"
page-height="11in"
page-width="8.5in"
margin-top="1in"
margin-bottom="1in"
margin-left="1in"
margin-right="1in">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:block
font-size="16pt"
font-weight="bold"
space-after="5mm">
Apache FOP Proof of Concept.
</fo:block>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
ログファイルに次のメッセージが表示されます。
FATAL ERROR: 'com.ibm.xtq.common.utils.WrappedRuntimeException: D:\Program Files\IBM\Domino\<document form='PO'>
エラーは、変換しようとしているログ内の XML 全体をエコーし、次のように終了します。
(The filename, directory name, or volume label syntax is incorrect.)'
Domino が XML をパスに含めようとしていることに注意してください。これが間違っていることはわかっていますが、修正するために何をすべきかわかりません。
編集: これは、変換を実行する Java クラスです。このコードは、Paul Calhoun のデモからのものです。
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
public class DominoXMLFO2PDF {
public static void getPDF(OutputStream pdfout,String xml,String xslt, Boolean authReq, String usernamepass) {
try {
//System.out.println("Transforming...");
Source xmlSource,xsltSource; //Source xmlSource = new StreamSource("http://localhost/APCC.nsf/Main?ReadViewEntries&count=999&ResortAscending=2");
xmlSource = new StreamSource(xml); //Source xsltSource = new StreamSource("http://localhost/APCC.nsf/viewdata.xsl");
xsltSource = new StreamSource(xslt);// configure fopFactory as desired
final FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
// Setup output
// OutputStream out = pdfout;
// out = new java.io.BufferedOutputStream(out);
try {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF,foUserAgent, pdfout);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSource);
//transformer.setParameter("versionParam", "Company List"); // Set the value of a <param> in the stylesheet
Source src = xmlSource; // Setup input for XSLT transformation
Result res = new SAXResult(fop.getDefaultHandler()); // Resulting SAX events (the generated FO) must be piped through to FOP
transformer.transform(src, res); // Start XSLT transformation and FOP processing
} catch (Exception e) {
} finally {
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
このコードは、次の行を使用して xAgent で呼び出されます。
var retOutput = jce.getPDF(pageOutput, xmlsource, xsltsource, authReq, usernamepass);
xmlsource は、メソッドが Document.generateXML() を使用して XML を返す次の行で設定されます。
var xmlsource = statusBean.generateXML(POdata, sessionScope.unidPDF);