I'm trying to convert a docx file to an HTML file using the given sample program.
The sample suggests:
String userCSS = "html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, img,
ol, ul, li, table, caption, tbody, tfoot, thead, tr, th, td " +
"{ margin: 0; padding: 0; border: 0;}" +
"body {line-height: 1;} ";
htmlSettings.setUserCSS(userCSS);
Even though setUserCSS is a depreciated method.
This works fine, but I have my own css file that I would like to use.
I would like to avoid extracting it as a string from the file where possible.
As well as this, I would like to combine multiple css files such that the top of the resultant output html contains:
<link rel="stylesheet" type="text/css" href="stylesheet1.css"/>
<link rel="stylesheet" type="text/css" href="stylesheet2.css"/>
<link rel="stylesheet" type="text/css" href="stylesheet3.css"/>
in the head.
That, or finding an alternative to the setUserCSS method that I can call on the HTMLSettings class.
Couldn't find much for this case, only for the other way around. Any solution is appreciated. Thanks.
I don't know which language are you using to write such kind of program. But you can do that by just writing a function that would convert the path of a file into css link.
For example:
htmlSettings.loadCSS('path/stylesheet1.css');
this will converted to
<link rel="stylesheet" type="text/css" href="path/stylesheet1.css"/>
The focus of docx4j's HTML output is on creating CSS based on the formatting in the document.
That said, if the HTML is being created via XSLT, the relevant code is in the createStyleElement method in XsltHTMLFunctions.java
If you are using the non-XSLT approach, it is in HTMLExporterVisitorDelegate.
Related
I've a Java WebApp. I have put some attributes inside the context and init params to get them when I needed.
Content of head.jspf:
<link href="${initParam['bootstrap_css_cdn']}" rel="stylesheet" media="screen">
<link href="${applicationScope['css_dir']}basic.css" rel="stylesheet" media="screen">
From index.jsp, if I do this:
<jsp:include page="WEB-INF/jspf/head.jspf" />
it works perfectly!
But if I do this:
<jsp:include page="${applicationScope['headURL']}"
it doesn't work at all (the "headURL" variable is a string with the right URL). I mean, the jspf is included but, for example, the following code is written in the final html code literally:
${applicationScope['css_dir']}
What am I doing wrong?
#JBMizet wrote in a comment:
JSPF files are not compiled. They're supposed to be included statically, not dynamically (i.e. with <%#include %>). Change the extension to .jsp if you want a dynamic include.
This is where i put my css file:
This is how i register this resource:
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
This is how i references this css from the JSP:
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet"/>
I can see the JSP page with content but without styling.
I think the error is while referencing but i cant find it. I have tried also these, but does not work:
<link type="text/css" href="../css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="/resources/css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="<%=request.getContextPath() %>/css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="<%=request.getContextPath() %>/resources/css/bootstrap.css" rel="stylesheet"/>
Any idea?
EDIT: Now i have moved the css folder to WebContent. It seems like this:
It still does not work. What should i register for the ResourceHandler?
registry.addResourceHandler("/WEB-INF/**").addResourceLocations("/WEB-INF/"); ?
How should i reference the css from the JSP?
The resource handler doesn't look for resources on the class path, by default. It looks for them in the webapp.
Create a folder called resources and put it in /src/main/webapp. Then put your css, js, etc. folders in there.
The files under src cannot be accessed on default condition , you should put these assets into WebContent directory.
Resources usually means config proppertis like properties and xml, they will be used by the
java code, assets usually mean that can be accessed by the browser directly,Notice that WEB-INF is protected,you need to put your css directory under WebContent, except for WEB-INF
for exampel,you can put your css directory under /WebContent/assets/
And add these code at the head of your jsp pages
<%
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath();
%>
<link type="text/css" href="<%=basePath%>/assets/css/bootstrap.css" rel="stylesheet"/>
It's not good to use relative path!!
I installed playframework and have a question.I looked at the helloworld tutorial but it seems to use groovy.
#(message: String)
#main("Welcome to Play 2.1") {
#play20.welcome(message, style = "Java")
}
The first line is the function definition. What does play20 stand for. I am really new to Scala and I cant make head or tail out of it.
#(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>#title</title>
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="#routes.Assets.at("images/favicon.png")">
<script src="#routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
</head>
<body>
#content
</body>
</html>
This is just standard HTML which accepts html content and a title string. But how is this file getting called from the index.scala.html?
The #play20.welcome() part calls a Scala method, not that different from Java.
As for the HTML templates, they're compiled into Scala classes as well, a bit like JSP is compiled into servlets.
The example you are refering to sounds like it's about Play 1, while the framework you are trying out is play 2, which is a rather different thing. Play 2 has it's own template engine.
The # is the symbol that signals you're going to start a Scala expression. Like < ?php ? > or <% %> for intance in other langauges. The only difference is that you don't have a trailing symbol, because the template engine stops parsing at the end of the expression and automagicly returns to evaluating the template as html.
play20 is an object that is in scope for the template engine, like things in java.lang are in in scope in a regular java file. E.g. String.
In this case play20 is like a class with a static method in Java.
In this tutorial you have good simple introduction to how to use the Play 2 framework
I need to find the link tag using Regex.
I have this line in my html file.
<link rel="stylesheet" href="<c:url value="/styles/folders/masterTree.css" />" type="text/css" media="screen, print" />
I need a regex expression to find this.
This is not a homework. I need this as part of my office requirement.
Thanks to all in advance.
Using regex to parse html can be problematic as most (x)html is not actual valid.
Because of all the edge cases you end up with it breaking before long.
You don't specify what language you are developing in but if you are working in .net I would suggest looking into using HtmlAgilityPack:
http://runtingsproper.blogspot.com/2009/09/htmlagilitypack-article-series.html
You shouldn't. A real HTML parser is the only reliable way to parse HTML.
I need to make a link which opens print version of current page in a new tab. I already have correspondent css-file. But I don't know how to specify when this file should be used instead of standard.
The simplest way is quite good. If I was using JSP I would simply add get parameter to print-link URL. Is there any way to achieve similar results with jsf?
Use EL to specify the CSS file dynamically, here's an example which checks the presence of the print request parameter (thus, <h:outputLink value="page.jsf?print" target="_blank"> would suffice):
<link rel="stylesheet" type="text/css" href="${not empty param.print ? 'print.css' : 'normal.css'}" />
You can also retrieve it as a bean proprerty the usual JSF way:
<link rel="stylesheet" type="text/css" href="<h:outputText value="#{bean.cssFile}" /> " />
If you're on Facelets instead of JSP, then you can also use unified EL in template text:
<link rel="stylesheet" type="text/css" href="#{bean.cssFile}" />
If you actually don't need a "print preview" tab/page, then you can also just specify the media attribute in the CSS link and let the link/button invoke window.print() during onclick instead of opening in a new tab.
<link rel="stylesheet" type="text/css" href="normal.css" media="screen, handheld, projection" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
When the page is about to be printed, the one specified by media="print" will automatically be used instead.
You can add get parameters to any JSF link by using the f:param tag.
<h:outputLink value="/somepage.xhtml" target="_blank">
<h:outputText value="Link to Some Page"/>
<f:param name="someparam" value="somevalue">
</h:outputLink>
This will render something basically like this:
Link to Some Page
You can add multiple params with more f:param fields. Alternatively, if it's static, you can just add it as part of the outputLink itself.
<h:outputLink value="/somepage.xhtml?someparam=somevalue" target="_blank">
<h:outputText value="Link to Some Page"/>
</h:outputLink>
The problem, of course, being that you cannot do this and trigger server-side events. I've yet to figure out how to do this from a POST back and get it in a new tab.