wkhtmltopdf – Generating PDF and Images
wkhtmltopdf is amazing open source (LGPLv3) command line tool wkhtmltopdf to render HTML to PDF and various image formats using the Qt WebKit rendering engine. These run entirely “headless” and do not require any service.
There is also a C library, if you’re into that kind of thing.
How to use wkhtmltopdf ?
- Download a precompiled binary or build from source
- Create your HTML document that you want to convert into a PDF (or image)
- Run your HTML document through the tool.
For example, if I really like the treatment LiferayUI has done to their logo today and want to capture it forever as a PDF:wkhtmltopdf https://liferayui.com liferayui.pdf
Global Options: --collate Collate when printing multiple copies (default) --no-collate Do not collate when printing multiple copies --cookie-jar <path> Read and write cookies from and to the supplied cookie jar file --copies <number> Number of copies to print into the pdf file (default 1) -d, --dpi <dpi> Change the dpi explicitly (this has no effect on X11 based systems) -H, --extended-help Display more extensive help, detailing less common command switches -g, --grayscale PDF will be generated in grayscale -h, --help Display help --htmldoc Output program html help --image-dpi <integer> When embedding images scale them down to this dpi (default 600) --image-quality <integer> When jpeg compressing images use this quality (default 94) --license Output license information and exit -l, --lowquality Generates lower quality pdf/ps. Useful to shrink the result document space --manpage Output program man page -B, --margin-bottom <unitreal> Set the page bottom margin -L, --margin-left <unitreal> Set the page left margin (default 10mm) -R, --margin-right <unitreal> Set the page right margin (default 10mm) -T, --margin-top <unitreal> Set the page top margin -O, --orientation <orientation> Set orientation to Landscape or Portrait (default Portrait) --page-height <unitreal> Page height -s, --page-size <Size> Set paper size to: A4, Letter, etc. (default A4) --page-width <unitreal> Page width --no-pdf-compression Do not use lossless compression on pdf objects -q, --quiet Be less verbose --read-args-from-stdin Read command line arguments from stdin --readme Output program readme --title <text> The title of the generated pdf file (The title of the first document is used if not specified) -V, --version Output version information and exit
Additional options
That’s amazing, I’ve always wanted to turn LiferayUI homepage into a PDF, but I want a table of contents as well.
There are lot’s of command line options. You can check out the auto-generated wkhtmltopdf options.
You can also add custom Header and Footer in PDF using page option.
wkhtmltopdf --header-html header.html https://liferayui.com liferayui.pdf
Bootstrap 3 with Liferay 6.2
In Current Liferay version 6.2 we have bootstrap 2.3.2 as default theme library.Bootstrap 3 was released on August 19th, 2013, before releasing Liferay 6.3. Bootstrap 3 completely dropped support for IE7 and below. While Liferay 6.2 provided limited support for IE7 and below. So here are some of the distinctive differences between Bootstrap v2.3 and v3.0:
Bootstrap 3 |
Bootstrap 2.3.2 |
Grids: Fluid (480px, 768px, 992px, 1200px) | Flat Design: Gradients are no longer available in V3.0 |
Grids: Fluid and fixed (724px, 940px, 1170px; below 768px are single column and vertically stacked) | CSS3 gradients and box shadows |
Columns Classes: .col-xs-1, .col-sm-1 .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2 .col-md-2, .col-lg-2 | .span1,.span2 |
For know more in detail please go to this link:- http://getbootstrap.com/migration/
Creating Theme with Bootstrap 3 in Liferay 6.2
These are some basic steps for creating Theme with Bootstrap 3. In some of the steps are same except few additional Steps.
- In Liferay Devloper Studio, Go to –> File – New – Liferay Plugin Project.
- Provide the Name inside Project Name Text Box (say Test).
- Select the Plugin Type as – Theme and click Next.
- Select Theme parent – _styled and Theme framework – Velocity. Click Finish.
- A new Theme (Test-theme) will be created.
- Inside _diffs folder create css, images, js and templates folder.
- Copy and paste the required files in the corresponding folders as needed.
- Download Bootstrap 3 CSS file and place it inside _diffs – css
- Open Main.css and call the Bootstrap 3 css file above custom.css
- Modify the files as explained.
Liferay 6.2 Basic Structure: [Two Column Layout]
<div id="main-content" role="main"> <div class="portlet-layout row-fluid"> <div class="span6 portlet-column portlet-column-first" id="column-1"> $processor.processColumn("column-1", "portlet-column-content portlet-column-content-first") </div> <div class="span6 portlet-column portlet-column-last" id="column-2"> $processor.processColumn("column-2", "portlet-column-content portlet-column-content-last") </div> </div> </div>
These are the some comman classes who are conflict with Bootstarp 2.3 in liferay 6.2.
.signed-in .collapse { display:block; } .lfr-edit-layout-panel .collapse{ display:block; } .dockbar.navbar-static-top .collapse { display: block; } .navbar-inner .collapse{ display:block; } .dockbar-ready #wrapper { margin-top: 149px; } .dockbar-ready section#content { padding: 0 0 0 0; } .dockbar.navbar-static-top { background-color: transparent; padding: 0px; } .dockbar-messages{ display:none; } .lfr-device-preview{ z-index: 1000; } .modal{ display:block; } .modal-hidden{ display:none; }
Animated layouts in Liferay using Isotope JS
This article will help you to learn and how we can use isotope javascript library in our project. Isotope javascript library who developed by the David DeSandro. Isotope provides animated sorting and filtering in UI elements. It uses Masonry and packery layouts in addition to other layouts.
I found both of them before some days when i started working in one of my project and it’s so amazing, I whipped up a few demos to see for myself!
Install Isotope
For installation we need to download these isotope library from isotope website.
- isotope.pkgd.js un-minified, or
- isotope.pkgd.min.js minified
Package managers
- Install with Bower: bower install isotope –save
- Install with npm: npm install isotope-layout
Configuring Isotope
Portal_nirmal.vm
Include the Isotope .js file in your Theme.
<script src="${themeDisplay.pathThemeJavaScript}/isotope.pkgd.js"></script>
After create a theme you can create a portlet with the name of isotope-layout for writing your HTML. write initialization code in your theme main.js file.
Initializing isotope with Jquery:
$('.isotope-grid').isotope({ // options itemSelector: '.items', layoutMode: 'fitRows' });
Initialize with Vanilla JavaScript:
var elem = document.querySelector('.isotope-grid'); var iso = new Isotope( elem, { // options itemSelector: '.items', layoutMode: 'fitRows' }); // element argument can be a selector string // for an individual element var iso = new Isotope( '.isotope-grid', { // options });
Initialize in HTML:
You can initialize Isotope directly in HTML, without writing any JavaScript or Jquery. You have to just add js-isotope to the class of the container element. For adding the options you can add data-isotope-options attribute in your element.
How to use Filtering,Sorting and Layout
Using Isotope you can hide and show item elements with the filter option. Which shows the only matched items according to the filter. Here you can see how we can apply the filters on:
Selectors(Like Class and id)
$grid.isotope({ filter: '.ClassName' });
jQuery selectors(if jQuery is present)
// filter .ClassName items that are NOT .transition class
$grid.isotope({ filter: ‘.ClassName:not(.transition)’ });
With Functions
$grid.isotope({ // filter element with numbers greater than 50 filter: function() { // _this_ is the item element. Get text of element's .number var ClassName = $(this).find('.ClassName').text(); // return true to show, false to hide return parseInt( ClassName, 10 ) > 50; } })
UI with Buttons
<button data-filter="numberGreaterThan50">number > 50</button> <button data-filter="ium">name ends with -ium</button>
// init Isotope var $grid = $('.grid').isotope({ // options }); // filter items on button click $('.filter-button-group').on( 'click', 'button', function() { var filterValue = $(this).attr('data-filter'); $container.isotope({ filter: filterValue }); });
Sorting
In Sorting we are using two methods getSortData() and SortBy().
For more Information: Sorting
layout
In Layout all sizing and styling of items is handled by your own CSS so when we are developing the responsive layouts then we need to set item sizes with percentages in css and also we need to change the mode of layout with masonry and set the percentage-width columnWidth with element sizing. Setting up the percentPosition option true (percentPosition: true) reduce the adjustment transitions on responsive mode.
For more Information: Layout
Getting started AngularJS with Liferay Portal
After reading the title of this post the first question comes in your mind is “Can we use AngularJS with Liferay?”
and my answer is yes we can. Now your thinking why AngularJS? I will give the answer of your all questions in this article.
What is AngularJS?
Angular js is open source web application development framework developed by Misko Hevery and maintained by Google. AngularJS architecture based on MVC(Model – View – Controller). MVC pattern help you to manage separately presentation, data, and logic components. server-side services are offered by Angular, like view-dependent controllers, to client-side web applications.
These are the some remarkable features:
- HTML Declarative approach:This feature help you to declaring dynamic views in static web-applications. For your application, AngularJS facilitates you to extend HTML vocabulary. The consequential ssetting is especially expressive, readable, and quick to develop.
- Easy Data Binding : AngularJS Two-way data binding is its most distinctive feature, and it reduces the amount of write dynamic code.
- Reusable Components: Using AngularJS directives help you to make your component reusable.
- Dependency Injection: You can easily inject dependencies of other modules in your web Application. Dependency injection is also a core to AngularJS.
- End to end Integration Testing / Unit Testing: While writing a code for application, we also need write test cases. Angular is designed makes testing your application easy by using dependency Injection feature that makes testing components much easier then any other frameworks. Jasmine and Karma are the testing tool which we use in angular application
- Routing: This feature allows to make your SPA website much easier.
- Templating: Dynamically creating and updating HTML based on templates.
- Services: you can use server side services in angular to make your web application dynamic.
If you are thinking to develop Angular Web Application in LIferay Developer Studio then Before starting to write a code you must know how to configure AngularJS in your liferay. It’s reduce your efforts to develop and maintain your Angular Web Application in Liferay. You can also write individual portlet in AngularJS. So in this article i am going to make a Independent News List portlet with the help of JSON Array in Angular.
Creating a liferay portlet
- Go to the package Explorer > Right click New > Select Liferay Plugin Project
See Figure 1
If you want to setup AngularJS in Liferay developer studio. Read this article
or you can directly add the AngularJs Library in your theme or You can add directly in your portlet as well.
<script src="${themeDisplay.pathThemeJavaScript}/lib/angular.min.js"></script>
Now start write your code in portlet main.js file.
In this article you can see how Angular makes browsers intelligent— without the use of any other third party plugins.
What you Learn in this article:-
- Examples of how to use client-side data binding to build dynamic views of data that change immediately in response to user actions.
- See how Angular sync your data in view without the need for DOM manipulation.
- Learn a better, easier way to create AngularJS based portlet that works independently with your application
Getting Started
AngularJS is using HTML Declarative Approach to write and extend HTML code with custom attributes and elements. It’s also helps you to in Data Binding. You have to create one pure static HTML page then examine how we can convert this HTML code into a template that angular will use to display dynamic data.
So here is Static HTML code:-
<ul> <li> <a href="#"><img src="" alt="news-img"/></a> <div class="news-desc"> <h4></h4> <p></p> </div> </li> <li> <a href="#"><img src="" alt="news-img"/></a> <div class="news-desc"> <h4></h4> <p></p> </div> </li> </ul>
In AngularJS, the view is a magnification of the model through the HTML template so whenever we change anything in the model angular refreshes the same binding points and updates in the view.
The view component is frame by Angular from this template:
docroot/view.jsp:
<div ng-app="NewsListApp" class="NewsListApp"> <ul ng-controller="NewsListCtrl"> <li ng-repeat="news in newslist"> <a href="{{news.url}}" class="news-img"> <img src="{{news.img}}" alt="news-img"/></a> <div class="news-desc"> <h4><a href="{{news.url}}">{{news.title}}</a></h4> <p>{{news.desc}}</p> </div> </li> </ul> </div>
We replaced the HTML news list with the ngRepeat directive and Angular expressions:
- The ng-repeat=”news in newslist” attribute in the
- tag is an Angular repeater directive. The repeater tells Angular to create a
- element for each news in the list using the
- tag as the template.
- The expressions wrapped in curly braces {{ }} will be replaced by the value of the expressions.
We have added a new directive, called ng-controller, which attaches a NewsListCtrl controller to the parent tag.
- The expressions in curly braces {{ }} show bindings, which are referring to our NewsListApp model, which is set up in our NewsListCtrl controller.
Now Build your portlet. After completing successful build go to your browser open your localhost site and just drag the portlet in layout to see the result.
Note: We have specified to load Angular Module using ng-app=”NewsListApp”, where NewsListApp is the name of our module. This module will contain the NewsListCtrl.
How to configure AngularJS Plugin in Liferay
AngularJS IDE plugin is based on tern.java to manage powerful completion on HTML files (AngularsJS Expression, directive, modules) and Javascripts files.
Configure AngularJS Plugin in Liferay
AngularJS IDE Plugin help you to extend Liferay web development tool and enhance the capabilities of UI development in liferay:
- HTML editor which supports AngularJS expression and directive.
- Angular Explorer view which displays modules, controllers of your project in a tree structure.
- Javascript editor which supports AngularJS features (modules, etc).
Follow this below steps to configure the angularjs plugin in liferay
- Go to : Help > Click on Install New Software
- Copy and paste this URL in Work with textbox “Anularjs – http://oss.opensagres.fr/angularjs-eclipse/0.7.0/”
- Anularjs – http://oss.opensagres.fr/angularjs-eclipse/0.7.0/
We need to select only those components who are not installed on you Liferay Developer Studio.
Click on checkbox “Hide items that already installed”
Click on Next Button.
After installation of all the components you can convert your Project.
- Right click on your project > Configure > Convert to AngularJS Project
AngularJS Eclipse is based on the javascript inference engine tern.js is written in JavaScript. To use it You must configure node.js. You can also do it this with Rhino but it’s too slow for that .To do that you can :
- Now Go to Window > Prefrences > Select Tern:
when the native node is selected, in default folders installation, it explores node binary (ex : “C:\Program Files\nodejs\node.exe” for Windows) and if it doesn’t locate, it seeks in your node in your “PATH” environment. For that you have to set PATH enviroment in your system.
You can download node.js from this link. you must install the node.js according your OS Configuration :
Right Click on your Project properties and verify the angular plugin
Angular plugin will offer you to recover controllers,module, (custom) directives while writing a code. Here you can also see the list of other modules are available which we can select and enable as per the project requirement.
Set your Script path:
Settings of AngularJS Directives Syntax
Angular is using several syntax of declaring directives like starting with ‘x-‘, ‘data-‘ and use ‘:’, ‘-‘, ‘_’ delimiters.
Here ,we have finished to configure AngularJS IDE Plugin, now it’s time to write the code and start your first web application with Liferay.