飞碟中的外部CSS [英] External CSS in Flying Saucer

查看:43
本文介绍了飞碟中的外部CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Flying-Saucer中包括外部CSS.在此之前,我检查了 StackOverflow 中的所有可用链接,但它们没有帮助这就是为什么将这个作为我的自我.

I would like to know how to include the External CSS in Flying-Saucer.Before that THB I checked with all the available links in StackOverflow but they are not helpful.That's the reason why made this one my self.

TestCSS.xhtml 的重命名版本为 TestCSS.html .因此它们的内容是相同的.下面的图1是我在Eclipse IDE中的项目结构.如果运行TestCSS.html,它将在浏览器中将页面结果显示为图2.

TestCSS.xhtml renamed version of TestCSS.html.So content of them are same. Below (Image 1 ) is the Structure of my Project in Eclipse IDE.If I run the TestCSS.html it will give the page result as Image 2 in Browser.

以下是不能作为外部CSS起作用的代码:

Below are Code which are not working as External CSS :

This one Working :
<style>
.redFontClass
{
  color : red;
}
.blueFontClass
{
  color : blue;
}
</style>

This one NOT Working :
<link href="RedCSS.css" rel="stylesheet" type="text/css" />

This one NOT Working :
<link rel="stylesheet" 
href="http://localhost:8888/Fly-Sauccer-Web/css/RedCSS.css" type="text/css" />

This one NOT Working :
<link href="file:///C:/Users/Joseph.M/WorkPlace_Struts2/Fly-Sauccer-Web/WebContent/css/RedCSS.css"  rel="stylesheet" type="text/css" />

我尝试了所有方法,包括xhtml内css的绝对路径.但是css没有得到应用.请帮助我解决问题.

I tried with all the ways including absolute path of css inside of the xhtml also.but css is not getting applied.Please help me to fix the problem.

图片1

Image 1

图片2

Image 2

RedCSS.css

RedCSS.css

.fontClass
{
  color : red;
}

TestCSS.html

TestCSS.html

<html>
<head>
<link href="file:///C:/Users/Joseph.M/WorkPlace_Struts2/Fly-Sauccer-Web/WebContent/css/RedCSS.css"  rel="stylesheet" type="text/css" />
</head>
<body>
<b>This Should come assss <span class = "fontClass" >Red</span> </b>
</body>
</html>

Java代码:

public static void main(String[] args) throws Exception{

    // Path of Input File 
    String inputFile = "C:\\Users\\Joseph.M\\WorkPlace_Struts2\\Fly-Sauccer-Web\\WebContent\\TestCSS.xhtml";
    // Path of Output File 
    String outputFile = "C:\\Users\\Joseph.M\\WorkPlace_Struts2\\Fly-Sauccer-Web\\output.pdf";
    OutputStream os = new FileOutputStream(outputFile);             
    ITextRenderer renderer = new ITextRenderer();

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputStream is = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File(inputFile)));
    Document doc = builder.parse(is);
    is.close();
    renderer.setDocument(doc,null);        
    renderer.layout();
    renderer.createPDF(os);             
    os.close();
}

推荐答案

请参考此链接.它提到,当您要使用外部CSS文件时,应使用media ="print"属性在链接标记上.

Its mentioned that when you want to use an external css file, you should have a media="print" attribute on the link tag.

link href ="file:///C:/Users/Joseph.M/WorkPlace_Struts2/Fly-Sauccer-Web/WebContent/css/RedCSS.css"rel ="stylesheet"type ="text/css"media =打印"

link href="file:///C:/Users/Joseph.M/WorkPlace_Struts2/Fly-Sauccer-Web/WebContent/css/RedCSS.css" rel="stylesheet" type="text/css" media="print"

这篇关于飞碟中的外部CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆