This is almost straight forward implementation just follow few steps.
Step 1. Get the page url u want to print I am thinking I am on the same page
of which I wanted to print the content . Then I can get the url like this
PortletURL url = PortletURLUtil.getCurrent(renderRequest, mimeResponse or renderResponse);
else you can create the url of the page like this
PortletURL printPageURL = renderResponse.createRenderURL();
and set the required parameter related to youur page plus these extra parameters
printPageURL.setWindowState(LiferayWindowState.POP_UP);
printPageURL.setParameter("viewMode", Constants.PRINT);
sample url will look like this :
PortletURL printPageURL = renderResponse.createRenderURL();
printPageURL.setWindowState(LiferayWindowState.POP_UP);
printPageURL.setParameter("struts_action", "ur_stuts_action_path");
printPageURL.setParameter("ur_param_1", "ur_param_value_1");
printPageURL.setParameter("viewMode", Constants.PRINT);
printPageURL.setParameter("print", String.valueOf(true));
Step 2:
create a boolean variable print with default value false.
eg:
boolean print = ParamUtil.getBoolean(request,"print");
Step 3: Add this code on your page.
<c:choose>
<c:when test="<%= print %>">
<script type="text/javascript">
function printArticle() {
print();
}
</script>
</c:when>
<c:otherwise>
<script type="text/javascript">
function <portlet:namespace />printPage() {
window.open('<%= printPageURL.toString()%>', '', "directories=0,height=480,left=80,location=1,menubar=1,resizable=1,scrollbars=yes,status=0,toolbar=0,top=180,width=640");
}
</script>
</c:otherwise>
</c:choose>
Step 4: Add this code
<c:choose>
<c:when test="<%= print %>">
<span style="float:right">
<liferay-ui:icon image="Print" url="javascript:onclick=printArticle();" label="<%= false %>" />
</span>
</c:when>
<c:otherwise>
<span style="float:right">
<liferay-ui:icon image="Print" url='<%= "javascript:" + renderResponse.getNamespace() + "printPage();" %>' label="<%= false %>" />
</span>
</c:otherwise>
</c:choose>
Thats it
Enjoy !!!
Thursday, October 29, 2009
For preview without saving the article in Journal
Hi today I want to share how to implement preview without saving web-content in liferay.
Step 1:
Add following line
<input type="button" value="<liferay-ui:message key="preview" />" onClick="<portlet:namespace />previewArticleNoStructure();" />
Step 2:
write the following function
function <portlet:namespace />previewArticleNoStructure() {
document.<portlet:namespace />fm2.action = "<%= themeDisplay.getPathMain() %>/journal/view_article_content?<%= Constants.CMD %>=<%= Constants.PREVIEW %>&groupId=<%= String.valueOf(groupId) %>&articleId=<%= HttpUtil.encodeURL(articleId) %>&version=<%= version %>&languageId=" + document.<portlet:namespace />fm1.<portlet:namespace />languageId.value + "&type=" + document.<portlet:namespace />fm1.<portlet:namespace />type.value;
document.<portlet:namespace />fm2.target = "_blank";
document.<portlet:namespace />fm2.title.value = document.<portlet:namespace />fm1.<portlet:namespace />title.value;
document.<portlet:namespace />fm2.xml.value = <portlet:namespace />getArticleContentNoStructure();
document.<portlet:namespace />fm2.submit();
}
Step 3:
Write this function
function <portlet:namespace />getArticleContentNoStructure(){
var xsd = "<root available-locales=\"en_US\" default-locale=\"en_US\">";
xsd += "<static-content language-id=\"en_US\">";
xsd += "<![CDATA[";
xsd += window. xsd += "]]>";
xsd += "</static-content>";
xsd += "</root>";
return xsd;
}
that's it .
Enjoy!!!
Step 1:
Add following line
<input type="button" value="<liferay-ui:message key="preview" />" onClick="<portlet:namespace />previewArticleNoStructure();" />
Step 2:
write the following function
function <portlet:namespace />previewArticleNoStructure() {
document.<portlet:namespace />fm2.action = "<%= themeDisplay.getPathMain() %>/journal/view_article_content?<%= Constants.CMD %>=<%= Constants.PREVIEW %>&groupId=<%= String.valueOf(groupId) %>&articleId=<%= HttpUtil.encodeURL(articleId) %>&version=<%= version %>&languageId=" + document.<portlet:namespace />fm1.<portlet:namespace />languageId.value + "&type=" + document.<portlet:namespace />fm1.<portlet:namespace />type.value;
document.<portlet:namespace />fm2.target = "_blank";
document.<portlet:namespace />fm2.title.value = document.<portlet:namespace />fm1.<portlet:namespace />title.value;
document.<portlet:namespace />fm2.xml.value = <portlet:namespace />getArticleContentNoStructure();
document.<portlet:namespace />fm2.submit();
}
Step 3:
Write this function
function <portlet:namespace />getArticleContentNoStructure(){
var xsd = "<root available-locales=\"en_US\" default-locale=\"en_US\">";
xsd += "<static-content language-id=\"en_US\">";
xsd += "<![CDATA[";
xsd += window.
xsd += "</static-content>";
xsd += "</root>";
return xsd;
}
that's it .
Enjoy!!!
Subscribe to:
Posts (Atom)