题
首先,我不知道很多关于XSL。
我使用的是称为DITA生成PDF应用程序。其中一个它需要的东西是一个XSL文件的覆盖;添加自定义样式。
我试图添加使用相对路径外部图形。这是行不通的,除非我提供完整的路径。
不工作:
<fo:block text-align="center" width="100%">
<fo:external-graphic src="../../images/logo.png"/>
</fo:block>
是否工作:
<fo:block text-align="center" width="100%">
<fo:external-graphic src="/absolute/path/to/images/logo.png"/>
</fo:block>
我看着在网络上,它说,使用“文件:image.png”等网站上说用“URL(image.png)”,但既不工作
我在做什么错了?
解决方案
这是DITA-OT工作时经常被误解的老问题,但一些东西。结果 要知道,重要的是外部图形的路径是相对于DITA-OT artwork.dir。
我能想到的两种方法可以做到加贴标识。
的简单的方法
复制logo.png到arwork diretory
DITA-OT/demo/fo/cfg/common/artwork/logo.png
变更的xsl图形路径
<fo:block text-align="center" width="100%">
<fo:external-graphic src="Configuration/OpenTopic/cfg/common/artwork/logo.png"/>
</fo:block>
较硬的方式
有可能改变从其中取DITA它的图片以及将由FOP被用来渲染PDF的输出目录的艺术品目录。
打开build.xml文件
DITA-OT/demo/fo/build.xml
艺术品根
定义在根目录下DITA应艺术品复制到 缺省值是
<property name="artwork.dir" value="${dita.map.output.dir}"/>
这将设置root到您的最终PDF将被保存。
艺术品目的地
定义,其中文件应该相对于艺术品根目录被存储在路径
<copy todir="${coreArtworkDestinationDir}/Configuration/OpenTopic"
默认情况下它会创建文件夹/Configuration/OpenTopic
,然后在那里,包括子目录复制的一切。点击
确保更改目标的两倍。你必须编辑这两个地方只相隔几行。
艺术品源
定义,其中原始艺术品被保存,以便DITA-OT可以将文件复制到目的地。结果 第一行指向默认的艺术品来与DITA-OT,不应该被改变。
<fileset dir="${basedir}" includes="cfg/common/artwork/**/*.*"/>
第二个是用于定制从而具有应当被用于定制所述一个。
<fileset dir="${customization.dir}" includes="common/artwork/**/*.*"/>
在路径相对于DITA-OT /演示/ FO /定制。
其他提示
我也有类似的问题,而在另一个论坛,问题是分配“基本目录”路径的形式发现,因为基本目录路径必须有前缀“文件:”
下面C#中的方法来创建图像的PDF:
private string CreatePDF(string fileToCreate, string templateFile)
{
org.apache.fop.configuration.Configuration.put("baseDir", "file:" + AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["ImagesPath"] + @"\");
//Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(templateFile);
//Execute the transform and output the results to a file.
xslt.Transform(fileToCreate, "temp.fo");
FileInputStream streamFO = new FileInputStream("temp.fo");
InputSource src = new InputSource(streamFO);
string pdfFilesPath = ConfigurationManager.AppSettings["PDFFilesPath"];
if (!Directory.Exists(pdfFilesPath))
{
Directory.CreateDirectory(pdfFilesPath);
}
pdfFilesPath = AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["PDFFilesPath"];
string fileName = fileToCreate.Substring(fileToCreate.LastIndexOf(@"\") + 1, fileToCreate.LastIndexOf(".") - 1 - fileToCreate.LastIndexOf(@"\")) + ".PDF";
FileOutputStream streamOut = new FileOutputStream(pdfFilesPath + @"\" + fileName);
Driver driver = new Driver(src, streamOut);
driver.setRenderer(1);
driver.run();
streamOut.close();
return fileName;
}
问候! 加布里埃尔。
我说你有,你以为你是哪里的处理引擎认为它是之间的冲突。绝对路径始终工作。尝试验证“当前”的位置,你会看到发生了什么事情。
的路径相对于所述XML文档,而不是样式表的位置的位置。
您需要引用任何外部资源之前设置baseDir
。 这后可以帮助你这一点。