Search in sources :

Example 11 with HTMLDocument

use of elemental2.dom.HTMLDocument in project kie-wb-common by kiegroup.

the class PrintHelper method print.

public void print(final HTMLElement element) {
    final Window globalWindow = getGlobalWindow();
    final Window printWindow = globalWindow.open("", "_blank");
    final HTMLDocument printDocument = getWindowDocument(printWindow);
    writeElementIntoDocument(element, printDocument);
    changeMediaAttributesToAll(printDocument);
    copyStylesFromWindow(printDocument, globalWindow);
    setupPrintCommandOnPageLoad(printDocument, printWindow);
}
Also used : Window(elemental2.dom.Window) HTMLDocument(elemental2.dom.HTMLDocument)

Example 12 with HTMLDocument

use of elemental2.dom.HTMLDocument in project kie-wb-common by kiegroup.

the class PrintHelper method changeMediaAttributesToAll.

void changeMediaAttributesToAll(final HTMLDocument printDocument) {
    final NodeList<Element> links = printDocument.querySelectorAll("link");
    final String attribute = "media";
    for (int i = 0; i < links.length; i++) {
        final Element link = asElement(links.item(i));
        if (Objects.equals(link.getAttribute(attribute), "print")) {
            link.setAttribute(attribute, "all");
        }
    }
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement)

Aggregations

HTMLDocument (elemental2.dom.HTMLDocument)11 HTMLElement (elemental2.dom.HTMLElement)10 Test (org.junit.Test)9 HTMLBodyElement (elemental2.dom.HTMLBodyElement)5 Element (elemental2.dom.Element)4 Window (elemental2.dom.Window)4 DOMTokenList (elemental2.dom.DOMTokenList)3 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)1 Event (elemental2.dom.Event)1 Field (java.lang.reflect.Field)1