我正在尝试使用单一字体(FreeSans.ttf)进行普通,粗体和斜体,但simulate-style
功能似乎没有任何效果。
这是相关的字体配置:
<font kerning="yes" embed-url="FreeSans.TTF" simulate-style="true">
<font-triplet name="Free Sans" style="normal" weight="normal"/>
<font-triplet name="Free Sans" style="italic" weight="normal"/>
<font-triplet name="Free Sans" style="normal" weight="bold"/>
<font-triplet name="Free Sans" style="italic" weight="bold"/>
</font>
XSLT转型:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Free Sans">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm" margin-top="1cm" margin-bottom="1cm" margin-left="1cm" margin-right="1cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block>This <fo:inline font-weight="bold">document</fo:inline> is created with empty user stylesheet./fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
C#发布代码:
public static void Publish(string xslFoFile, string xConfFile, string outputFile, FopMode fopMode, bool cgmOption, NLog.Logger logger)
{
java.io.File xslFoFileFile = new java.io.File(xslFoFile);
java.io.File xConfFileFile = new java.io.File(HttpUtility.UrlDecode(xConfFile));
FopFactory fopFactory = FopFactory.newInstance(xConfFileFile);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
EventListener eventListener = new FopEventListener(logger);
foUserAgent.getEventBroadcaster().addEventListener(eventListener);
if (cgmOption)
{
IIORegistry.getDefaultInstance().registerServiceProvider(new CGMImageReaderSpi());
}
OutputStream outputStream = new DotNetOutputMemoryStream();
if (fopMode == FopMode.Fo2Pdf)
{
Fop fop = fopFactory.newFop("application/pdf", foUserAgent, outputStream);
var transformerFactory = new org.apache.xalan.xsltc.trax.TransformerFactoryImpl();
var transformer = transformerFactory.newTransformer();
StreamSource streamSource = new StreamSource(xslFoFileFile);
var saxResult = new SAXResult(fop.getDefaultHandler());
transformer.transform(streamSource, saxResult);
}
using (FileStream fileStream = System.IO.File.Create(outputFile))
{
var data = ((DotNetOutputMemoryStream)outputStream).Stream.ToArray();
fileStream.Write(data, 0, data.Length);
}
}
PDF渲染时没有任何消息或错误。