How to print IFRAME containing multi-page pages?

I would like to know if it is possible to print an HTML page containing an IFRAME that spans multiple pages. For some reason, the browser continues to trim the IFRAME after the first page. Here is a minimalist example demonstrating the problem described above. First, this is a simple HTML page containing an IFRAME that should be optimized for printing:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>TEST</title> <style> html, body { height: 100%; } iframe { width: 100%; height: 100%; } </style> </head> <body> <iframe src="iframe-content.html"> </iframe> </body> </html> 

And here is the page I want to embed:

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>TEST-CONTENT</title> </head> <body> <p> Some very, very long text spawning multiple pages. </p> </body> </html> 

Using JavaScript is not an option. I am looking for a solution that uses only CSS. Any help would be greatly appreciated.

+4
source share
2 answers

You can specify the parent document in the meta-document, because CSS is not able to specify the page to print, what it looks like.

 <link rel=alternate media=print href="printme.html"> 

If you are trying to print the entire iframe inside the parent, you need to insert a special CSS document for printing. using this together with print preview will help you set zero.

 <link rel="stylesheet" href="print.css" media="print"> 
0
source

Only CSS solution - you need to set the iframe width to a static size. For A4 Portrait, the width is about 670 pixels. For landscape printing, the value will be different.

 iframe { width: 670px; } 

Work in a chrome browser.

0
source

Source: https://habr.com/ru/post/1488090/


All Articles