skip to Main Content

I’m using ASP.NET WEBFORMS and Telerik and I want to export a document with Telerik components. I’m doing this with client export manager of Telerik https://demos.telerik.com/aspnet-ajax/client-export-manager/overview/defaultcs.aspx, and it works, but I need to render the entire DOM, then show to user, then user clicks on EXPORT button, and if I have more than one document it can be tedious for the user, so I want to export document without this preview, exporting the documents without user interaction. At this moment, I have seen this possible options:

  • Tried to export the DOM before showing to user (in Render() event for example) but I can’t execute this with JavaScript because the DOM is not fully rendered.
  • Tried iText library, but this is not working with Telerik components (like graphics or grids)

The only thing on my mind right now is using something like https://phantomjs.org/ to automate the process where the user clicks the button automatically.
Could someone tell me any other strategy that does not require a lot of programming time?

Edit:I tried Selenium to simulate the user interaction, but obviously when the file is downloaded it is saved on external navigator, there is a way to save it on the user’s navigator?

2

Answers


  1. Better way is to use jquery to print the entire page or the part of the document(HTML element).

    As jquery wait DOM to render fully to run code.

    Create a Javascript function to print the page/element and call that function when ever you want.

    <script>
    function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;
    
     document.body.innerHTML = printContents;
    
     window.print();
    
     document.body.innerHTML = originalContents;
     }
    
     $(document).ready(function(){
      printDiv('body')
     });
     });
     </script>
    

    Customize above code as your requirement.

    How to print HTML content on click of a button, but not the page?

    https://www.geeksforgeeks.org/how-to-execute-jquery-code/#:~:text=The%20purpose%20of%20using%20jQuery,can%20be%20taken%20by%20jQuery.

    Login or Signup to reply.
  2. I am not sure I follow your description 100%
    But your DOM is for sure fully rendered after:

    This Javascript snippet should allow you to do whatever you want after a complete page load:

    <script type="text/javascript">
        document.addEventListener('readystatechange', event => { 
                    if (event.target.readyState === "complete") {
                        alert("Dom is now fully rendered.");
                    }
                });
        </script>
    

    put your export command after the alert.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search