Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
Download html window object with JS

i have this iframe here, and i want to doanload the window page with pdf inside, js function print() only shows the page, i want to download it automatically, bellow is the full code (i tryed with jspdf too).

<iframe id="conteudoIframe" src="https://eproc.trf4.jus.br/eproc2trf4/controlador.php?acao=acessar_documento_publico&doc=41625504719486351366932807019&evento=20084&key=0562cc6eddee0cc4a81dd869f92328dceab34deeaa59f4a33c43da6361cf42d6&hash=08920b364dc8433ad071d6b10c7e3817"  name="superior" width="100%" height="560px"></iframe>

<script>

    downloadPdfFromIframe();

    function downloadPdfFromIframe() {
        var script = document.createElement('script');
        script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js';
        document.head.appendChild(script);
        script.onload = () => { setTimeout(download(), 20000); };

        function download() {

            var myIframe = document.getElementById("conteudoIframe").contentWindow;

            myIframe.focus();
            myIframe.print();
            myIframe.close();

            var pdf = new jsPDF();

            pdf.fromHTML(myIframe);
            pdf.save('test.pdf');

            return false;
        }
    }

</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Iframes are only a window to remote objects thus while viewing they are showing both the already downloaded html surround and the already downloaded PDF but the PDF is independent It may be downloaded before or after the frame, you can see the pdf behind the print html dialog. So the PDF is in a different application as seen in the second browser view of your HTML.

Thus you have to save/print either one at a time. Frame object or Pdf object, to get both is not impossible, just needs to be done with a suitable application (not browser). So just like here I have ScreenShots, those canvases can be easily saved or printed as PDF.

A Chrome based Browser viewing the iFrame for printing

enter image description here

A Firefox based Browser viewing the iFrame to print using any other method like open in a second application window.

![enter image description here

If you need to download the two parts outside a browser then use two Download Commands so here is my.pdf

enter image description here

curl -o my.pdf "https://eproc.trf4.jus.br/eproc2trf4/controlador.php?acao=acessar_documento_implementacao&doc=41625504719486351366932807019&evento=20084&key=0562cc6eddee0cc4a81dd869f92328dceab34deeaa59f4a33c43da6361cf42d6&hash=08920b364dc8433ad071d6b10c7e3817&termosPesquisados="
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!