0

I have a custom list with the form customized via Infopath. I wanted to be able to print the "Display Form" for any given item. I figured I could just go into the non-modal display form and print. However, when I tried this, the content of the form is only printed as far as it fits on a single page and is then cut off. The form is rather long, so this won't work.

Does anyone know why this is happening and how to fix it? The issue is occurring in IE9. I am unable to test it in any other browser, so I am unsure if the problem is browser-specific.

My initial thought was that some element on the page must have overflow set to hidden somewhere in the css. However, I found and changed this everywhere I could with no luck. I also tried updating any fixed height elements to auto. Still no luck.

0

After trying a million different things to get the display form to print correctly without truncating the table, I finally gave up and moved to js for a solution. I would still love a cleaner css-only fix if possible, but this works for me. As a bonus, this even works if the form is in a modal popup.

I added a content editor webpart to the display form and attached the following code to a button:

// open the current window in another tab
var mywin = window.open(document.location);

// IE doesn't fire an onload event for tabs opened with window.open so we must poll
function tryReady(){
    // get the main table containing the form
    var el = mywin.document.querySelector("[id*='__XmlFormView'] table");

    // check if the element exists yet
    if(el){ 
        // append the table directly to the body to remove it from all of the nesting
        mywin.document.body.appendChild(el);

        // remove the rest of the stuff from the screen
        mywin.document.body.removeChild(mywin.document.getElementById("aspnetForm"));

        // update overflow of body so nothing is cut off
        mywin.document.body.style.overflow = "visible";

        // print the window
        mywin.print();

        // printing complete.  close the window
        mywin.close();
    } else {
        // window not yet loaded.  wait a bit before trying again
        setTimeout(tryReady, 1000);
    }
}

tryReady();

It's a bit messier than I would like, but unfortunately IE (at least version 9) does not fire an onload event for a window opened with window.open. I have commented the code thoroughly to explain what I'm doing, but the short version is that I open the same window in a new tab. I then move the main table that contains the form out of its nesting and directly into the body. I then delete all of the other stuff off of the page and print.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.