Clean and fix html with HtmlCleaner java library

package com.origami.sgm.util;

import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.SimpleHtmlSerializer;
import org.htmlcleaner.TagNode;

/**
 *
 * @author Fernando
 */
public abstract class HtmlUtil {
    
    public static String cleanHtml(String htmlText){
        
        HtmlCleaner cleaner = new HtmlCleaner();
        
        CleanerProperties props = cleaner.getProperties();
        
        TagNode node = cleaner.clean(htmlText);
        
        SimpleHtmlSerializer htmlSerializer = new SimpleHtmlSerializer(props);
        
        // remove <?xml definition tag:
        String htmlResult = htmlSerializer.getAsString(node).replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim();
        
        return htmlResult;
    }
    
}
Advertisements

Hide html elements in browser print page with css

In your stylesheet add:

@media print
{    
    .no-print, .no-print *
    {
        display: none !important;
    }
}

Then add class=’no-print’ (or add the no-print class to an existing class statement) in your HTML that you don’t want to appear in the printed version, such as your button. I got this to work with ‘noPrint’ instead of ‘noprint’ (lowercase).