/    Sign up×
Community /Pin to ProfileBookmark

Simple resize and print image, and multiple image print

I am sure that this must be really simple but I’m not a java programmer and have absolutely no idea where to start. Please help.

I am using this code:

<script type=”text/javascript”>
var pwin;
function printImg() {
pwin = window.open(document.getElementById(“imgMain”).src,”_blank”);
setTimeout(“pwin.print()”,20);
}
</script>

I want to adapt it so that I can resize an image on print in one option and print multiple images in another option. I have no idea how to do this. Can anyone help? Many thanks.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@toicontienNov 18.2008 — To print more than one image:
[CODE]function ImagePrinter() {
var i = 0;
var end = arguments.length;

this.initImages();
this.initOptions();

while (i < end) {
this.addImage( arguments[i] );
i++;
}
}
ImagePrinter.prototype = {

images : null,
options : null,
window : null,

addImage : function(src) {
return this.images.push(src) - 1;
},

initImages : function() {
this.images = [];
},

initOptions : function() {
this.options = [
"width=400",
"height=400",
"scrollbars=yes",
"location=no",
"toolbar=no"
];
},

closeWindow : function() {
if (this.window && this.window.close) {
this.window.close();
this.window = null;
}
},

getImagesSource : function() {
var i = 0;
var end = this.images.length;
var src = "";

while (i < end) {
src += '<img src="'+this.images[i]+'">';
i++;
}
return src;
},

getOptions : function() {
return this.options.join(",");
},

openWindow : function() {
if (!this.window) {
this.window = window.open("", "_blank", this.getOptions() );
}
this.window.focus();
},

print : function() {
if (this.window) {
this.closeWindow();
}
this.openWindow();
this.window.document.write( this.getImagesSource() );
this.window.document.close();
this.window.onload = function() {
print();
};
}

};

var p1 = new ImagePrinter("img1.jpg", "img2.jpg", ... , "imgN.jpg");
p1.addImage("img.jpg");
p1.addImage("cereal.jpg");[/CODE]

Then in an onclick for a link or button, just call p1.print().
×

Success!

Help @shdale spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...