How do I print the screen centralised and for any orientatio

Get help using Construct 2

Post » Tue Jan 03, 2017 2:41 pm

As I know, I cannot control the printer and its configuration options, but I need to print the screen and the result needs to be centralised and fit for any orientation. Is it possible? I am using the "execute javascript" action and I am getting a snapshot for that.

Thanks in advance.
B
74
S
13
G
4
Posts: 1,005
Reputation: 8,053

Post » Tue Jan 03, 2017 10:45 pm

I know this is not a common situation (print something in the game) but I really need some advices here. I believe that someone knows if is possible to format the layout to get a good print or not.

Thanks in advance.
B
74
S
13
G
4
Posts: 1,005
Reputation: 8,053

Post » Wed Jan 04, 2017 5:22 am

Use a text box object and the anchor behaviour. Should give what you want
B
10
S
2
Posts: 5
Reputation: 560

Post » Wed Jan 04, 2017 5:23 am

Or do you mean like a screenshot ? If thats the case no clue sorry :(
B
10
S
2
Posts: 5
Reputation: 560

Post » Wed Jan 04, 2017 6:35 am

The JavaScript command "print()" will print the page. I guess you can also print an invisible page too using an iframe:
https://developer.mozilla.org/en-US/doc ... e/Printing

So from what I can tell you can snapshot the canvas and create a new page with JavaScript that has the snapshot red image and print it. To center the image on the page you'd use css as I understand it.

At least that's the right direction to start tinkering.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Wed Jan 04, 2017 10:40 am

R0J0hound wrote:The JavaScript command "print()" will print the page. I guess you can also print an invisible page too using an iframe:
https://developer.mozilla.org/en-US/doc ... e/Printing

So from what I can tell you can snapshot the canvas and create a new page with JavaScript that has the snapshot red image and print it. To center the image on the page you'd use css as I understand it.

At least that's the right direction to start tinkering.


Thanks for the suggestions @R0J0hound

I tried to follow the @Magistross suggestion in this post: how-do-i-send-content-to-the-user-s-printer-from-the-layout_t110978?start=20

Code: Select all
"var iframe = document.getElementById(""iframe"");
if(!iframe) iframe = document.createElement(""iframe"");
iframe.frameBorder=0;
iframe.width=""0px"";
iframe.height=""0px"";
iframe.id=""iframe"";
iframe.setAttribute(""src"", ""about:blank"");
document.body.appendChild(iframe);
var image = new Image(); image.src = """ & CanvasSnapshot & """; $(""#iframe"")[0].contentWindow.document.open(); $(""#iframe"")[0].contentWindow.document.appendChild(image); $(""#iframe"")[0].contentWindow.document.close();
window.frames[""iframe""].focus();
window.frames[""iframe""].print();"


But nothing happened. Maybe because this is an old post.

I cannot understand why the image appears with a large left margin when I try to print it and why it does not fit on the page if I am using an image with 800x600 resolution.
B
74
S
13
G
4
Posts: 1,005
Reputation: 8,053

Post » Tue Jan 17, 2017 1:28 am

This was more painful to figure out than it should have been. You can change the css of the canvas to cover the page.
Code: Select all
"var style = document.getElementById('c2canvas').style;
style.position='fixed';
style.left=0;
style.top=0;
style.height='1in';
style.width='1in';
print();"


So you'd just change the canvas size and scroll before running that javascript code. You'll want to restore the css values to what they were before after that.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993


Return to How do I....?

Who is online

Users browsing this forum: Armench, Artcadev, farsen, newt and 14 guests