Printing with pagebreaks from a hype web page


(stefan hannan) #1

Hi There,

I am looking to create an online report, which will be very easy to create in Hype and then export to HTML and put online. I am planing to create each page in separate scenes, with a forward and back button to flick through the pages of the report.

The potential issue is that I would like to be able to print the full document directly from the browser.

I understand there is window.print() function that will allow the current page to be printed, but as I understand this would not print all of the scenes, only the active scene.

Is there any way to allow all scenes to be printed with a simple function? I have read that it may be possible with PHP using the .load function?

Many thanks in advance.

Stefan


#2

The short answer is no.

A Tumult Hype document displays one scene at a time, so you would need to embed multiple Hype documents (pulling your scenes out into separate documents) to print them. This ‘page-break’ css property might be useful to set on your Hype divs. One other option is to print separate PDF pages, and then combine it later. So you would go to scene 1, print as PDF, go to scene 2, print as PDF… then combine them all into one PDF.

One thing that might be useful: You can use Media Queries to change the style of your elements for printing.
When printing our documentation, this CSS is set as a Media Query:

	@media print and (color) {
	* {
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}
	@media print {
		/* Write out URLs after the URL in case document or PDF is ACTUALLY printed */
		a {
			font-weight: bolder;
			text-decoration: none;
		}
		a[href^=http]:after {
			content: " <" attr(href) "> ";
		}
		a.profeature:after {
			content: ""
		}
		#tumult-hype-documentation:after {
			content: url(https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl=https://tumult.com/hype/documentation/&choe=UTF-8);
			position: absolute;
			right: 0;
			top: 0;
		}
		.menu, .tocify-wrapper, #nav-button {
			display: none;
		}
		body {
			color: #ffffff;
		}
		.content {
			color: black;
		}
		.page-wrapper {
			margin-left: 10px;
		}
	}

You can also run JavaScript before printing :page_with_curl:

var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
    if (mql.matches) {
        // do something here! 
    }
});

(Mark Hunte) #3

Just been creating this… I wrote something like this a while back to use in my Office.

I wanted to keep it all in Native Hype.

The simple idea is to make your scenes as normal.
Then add a final last print scene.

The Last scene (we will call ‘Print’ ) will have the height of the combined height of all the other scenes.
i.e the normal scenes above it are each 800px.

So 800 * 4 =3200

We set the scene height just over that to 3210px.

Now we add some widgets down the length of the print scene. 4 in total.
One for each scene. The widgets each have a height of 800px to match a scene’s height and we do not get any slopping about in the widget/iframe.

Each widget is set to go to a specific url.

The URLs I have set in the example are.

./scene1/scene1.html
./scene1/scene2.html
./scene1/scene3.html
./scene1/scene4.html

These will be the paths to the individual scenes we export later.


Javascript

The 4 main scenes are set to run this JS on scene load.

This is optional depending on how you do things.

Each of the four main scenes have a print button and some nav buttons.

We do not want them showing up when the scenes load in the widgets on the print page so the JS hides these buttons only if the scene is loaded in a widget.

All the buttons are symbols and share the same class name.

	 if ( window.self !== window.top ){
	 
 
  
 var array = document.getElementsByClassName('hide') //— WE GET AN ARRAY OF THE CLASS OBJETCS

for (i = 0; i < array.length; i++) { 
 array[i].style.display = "none";;
}
    
  
 }

The print Scene JS

The print scene just get code to print.

I have inserted the print command inside a setTimeOut().
This gives the scene time to load.

You probably can check if the scene has loaded before firing the print command…

setTimeout(function(){ window.print() ; }, 2000);


Finally.

We export the Project as normal.

We then use the Advanced Export to export the individual scenes/slices.

When I exported, the slices were enclosed in another folder.
I took them out and placed them on the same level as the index page.

which gave me the paths like ./scene1/scene1.html
How you work out your paths is up to you.

PrintAllScenes_mhv1.zip (1.2 MB)


TIP:
If you want the print scene to revert back to the main doc, you can move the print() function call to the print scene’s time line actions. And then also place a timeline action a few seconds later ( about 3) to switch to anothe scene.
When the print function is called a dialogue is popped up for the printing, this effectivly pauses the timeline. When the diallogue is completed the timeline starts off again and jumps the scene.

Example.
PrintAllScenes_mhv2.zip (1.2 MB)


(stefan hannan) #4

Thanks for your response so far. Ive tried everything i can personally think of but cannot get anything to work in Safari, chrome or firefox. Im very much a beginner at coding so might be missing obvious things.

Im trying to simply get this media query to work

@media print {
div {page-break-after: always;}
}

I have put this into the head HTML and also into the innerHTML and cannot get a simple rectangle to break to the next page when printed.

is there anything in Hype that I need to be aware of to make this work. I have also tried adding !important.

thanks again

Stefan


(Mark Hunte) #5

This needs to be inside style tags in the Head file.

<style>
@media print {
    div {page-break-after: always;}
}
</style>

Also using div as your seperator most likely will give you issues since most of the project is going contain many divs.
Probably better to give a class name.

If I remember right I was working on a newer version of the above so you do not need the exported htm but did not get the page-break-after: always to work in a way I was happy with.


(stefan hannan) #6

Hi Mark

Many thanks for you responses so far.

I have included the code in the style tags and tried the class name approach. I have tried putting the code in the head html as you have suggested above, and I have written the CSS directly inside the div tags also.

In summary i cannot get any option to work and have absolutely no idea what I am doing wrong. I will upload a very simple file to see if I am doing something stupid.

Thanks

Stefan


(stefan hannan) #7

file uploaded pageBreak.hype.zip (56.0 KB)

have added some random paragraphs and tried to page break before the h2 tags.


(stefan hannan) #8

Hi Mark

Regarding you PrintAllScenes example posted above, did you manage to get the individual pages to sit nicely on each printed page?

When I go to print the PrintAllScenes example above in Safari, the pages get cut off with large gaps between sections.

I haven’t managed to get the page-break-after CSS to work in hype as yet, i assume it is something to do with the absolute positioning hype. If you know any other workarounds i would be extremely grateful to hear them.

Cheers


(Mark Hunte) #9

I am having the same issue, no matter what I do I cannot get the page breaks working.

The @media css does work as I have .noprint{display: none!important; working on buttons.


(stefan hannan) #10

thanks Mark… Its good to know at least that I’m not missing something really obvious.

Im afraid that there may be no solution to this and an easily printable online report within Hype may be only a dream.

cheers


(Mark Hunte) #11

To note, I did get an example working outside of Hype. So it is something to do with the hype make up that is probably stopping it. Maybe @Daniel has an idea.