src/main/java/org/fit/layout/cssbox/CSSBoxTreeBuilder.java
protected BrowserCanvas renderUrl(URL url, Dimension pageSize) throws IOException, SAXException
    {
        DocumentSource src = new DefaultDocumentSource(url);
        pageUrl = src.getURL();
        InputStream is = src.getInputStream();
        String mime = src.getContentType();
        if (mime == null)
            mime = "text/html";
        int p = mime.indexOf(';');
        if (p != -1)
            mime = mime.substring(0, p).trim();
        log.info("File type: " + mime);
        
        if (mime.equals("application/pdf"))
        {
            PDDocument doc = loadPdf(is);
            BrowserCanvas canvas = new PdfBrowserCanvas(doc, null, pageSize, src.getURL());
            doc.close();
            pageTitle = "";
            return canvas;
        }
        else
        {
            DOMSource parser = new DefaultDOMSource(src);
            Document doc = parser.parse();
            pageTitle = findPageTitle(doc);
            
            String encoding = parser.getCharset();
            
            MediaSpec media = new MediaSpec("screen");
            //updateCurrentMedia(media);
            
            DOMAnalyzer da = new DOMAnalyzer(doc, src.getURL());
            if (encoding == null)
                encoding = da.getCharacterEncoding();
            da.setDefaultEncoding(encoding);
            da.setMediaSpec(media);
            da.attributesToStyles();
            da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
            da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
            da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT);
            da.getStyleSheets();
            
            BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, src.getURL());
            contentCanvas.getConfig().setLoadImages(false);
            contentCanvas.getConfig().setLoadBackgroundImages(false);
            contentCanvas.getConfig().setLoadFonts(false);
            contentCanvas.getConfig().setReplaceImagesWithAlt(replaceImagesWithAlt);
            contentCanvas.createLayout(pageSize);
            
            src.close();

            return contentCanvas;
        }
        
    }
protected BrowserCanvas renderUrl(URL url, Dimension pageSize) throws IOException, SAXException
    {
        DocumentSource src = new DefaultDocumentSource(url);
        pageUrl = src.getURL();
        InputStream is = src.getInputStream();
        String mime = src.getContentType();
        if (mime == null)
            mime = "text/html";
        int p = mime.indexOf(';');
        if (p != -1)
            mime = mime.substring(0, p).trim();
        log.info("File type: " + mime);
        
        if (mime.equals("application/pdf"))
        {
            PDDocument doc = loadPdf(is);
            BrowserCanvas canvas = new PdfBrowserCanvas(doc, null, pageSize, src.getURL());
            doc.close();
            pageTitle = "";
            return canvas;
        }
        else
        {
            DOMSource parser = new DefaultDOMSource(src);
            Document doc = parser.parse();
            pageTitle = findPageTitle(doc);
            
            String encoding = parser.getCharset();
            
            MediaSpec media = new MediaSpec("screen");
            //updateCurrentMedia(media);
            
            DOMAnalyzer da = new DOMAnalyzer(doc, src.getURL());
            if (encoding == null)
                encoding = da.getCharacterEncoding();
            da.setDefaultEncoding(encoding);
            da.setMediaSpec(media);
            da.attributesToStyles();
            da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
            da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
            da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT);
            da.getStyleSheets();
            
            BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, src.getURL());
            contentCanvas.getConfig().setLoadImages(false);
            contentCanvas.getConfig().setLoadBackgroundImages(false);
            contentCanvas.getConfig().setLoadFonts(false);
            contentCanvas.getConfig().setReplaceImagesWithAlt(replaceImagesWithAlt);
            contentCanvas.createLayout(pageSize);
            
            src.close();

            return contentCanvas;
        }
        
    }
===================================================================