/    Sign up×
Community /Pin to ProfileBookmark

‘print’ and ‘download’ links

I keep thinking there [I]has[/I] to be a way to do this, but I can’t figure it out for the life of me.

I need to make a link that says “print” that prints a specified file (either a doc file or a jpg), and I need another link that says “download” that automatically downloads or opens the ‘save as’ window for either a jpg or pdf. Or would it need to be an exe to automatically save rather than opening?

Any ideas? Is this even possible? I’m thinkin’ it has to be, and yet I can’t find a single website that utilizes those features. The closest thing I can find is a flash movie that has a print button.

Andy Oliphant
A&M Design Studios

to post a comment
HTML

15 Comments(s)

Copy linkTweet thisAlerts:
@ray326Dec 10.2003 — You can only print the page loaded into the browser.

You can only force a save-as rather than display by sending a Content-type header that the browser doesn't know how to handle. Generally that's an application/octet-stream but you have to have full control over your HTTP response to make that happen for common file extensions like jpg, doc or pdf.
Copy linkTweet thisAlerts:
@metallibangerauthorDec 10.2003 — So you're sayin' I'm screwed... Is there any way to use some kind of 'onLoad' command to send the current page to the printer as soon as it's loaded? That could work for my purposes I suppose, although I know that's getting out of the realm of html and into java scripting. That's fine though.

The problem is, I'm trying to make a webpage for someone who is directing it to internet-stupid people, who theoretically don't even know how to right click. This person wants there to be obvious 'print' and 'download' links underneath every picture, document, or sound file so the visitors don't even have to think. If they want something from the page, all they need to do is hit 'download' and it's theirs. I'm beginning to fear that I promised something I'm not capable of doing...

Andy Oliphant

A&M Design Studios
Copy linkTweet thisAlerts:
@hammerslaneDec 10.2003 — [i]Originally posted by ray326 [/i]

[B]You can only print the page loaded into the browser.[/B][/QUOTE]
this is wrong. it is definitely possible to set the browser to print a different page to which is loaded. you don't even have to load the page that you want to print.

you simple load a bit of code [which i'm finding at the moment] into the <head>, and then you just have a normal javascript print link.

i'll get back to you.
Copy linkTweet thisAlerts:
@hammerslaneDec 10.2003 — yea. what he said....

if you dont want to use php to print a document, then this code within the <head></head> tag.
&lt;link rel="alternate" media="print" href="printerfriendly.html" /&gt;then this code below will create the button, which will print [in this case] 'printerfriendly.html'. &lt;script language="Javascript1.2"&gt;

var message = "Click here to print out a printer-friendly version";

function printpage()
{
window.print(); <br/>
}

document.write("&lt;form&gt;&lt;input type=button "+"value=""+message+"" onClick="printpage()"&gt;&lt;/form&gt;");

&lt;/script&gt;
Copy linkTweet thisAlerts:
@pyroDec 10.2003 — [i]Originally posted by hammerslane [/i]

[B]yea. what he said....[/B][/QUOTE]
The code I gave was to force the download, not print the page. The problem with using any code like what you gave is that it is just setting an alternate document to print, so they will no longer be able to print the original page.
Copy linkTweet thisAlerts:
@ray326Dec 10.2003 — [i]Originally posted by hammerslane [/i]

[B]this is wrong. it is definitely possible to set the browser to print a different page to which is loaded. you don't even have to load the page that you want to print.

you simple load a bit of code [which i'm finding at the moment] into the <head>, and then you just have a normal javascript print link.



i'll get back to you. [/B]
[/QUOTE]

Ok, will you feel better if it reads, "You can only print [b]a[/b] page that's loaded by the browser?"
Copy linkTweet thisAlerts:
@hammerslaneDec 10.2003 — apologies if i came across as a bit arrogant... i feel happy that i'm trying to help. you weren't wrong as such, i just wanted to clearly put across what i knew...

regards
Copy linkTweet thisAlerts:
@ray326Dec 10.2003 — [i]Originally posted by metallibanger [/i]

[B]So you're sayin' I'm screwed... Is there any way to use some kind of 'onLoad' command to send the current page to the printer as soon as it's loaded? That could work for my purposes I suppose, although I know that's getting out of the realm of html and into java scripting. That's fine though.[/b][/quote]

Yes, that's doable as long as the browser's Javascript supports window.print() and most of them do.
Copy linkTweet thisAlerts:
@metallibangerauthorDec 10.2003 — Ahh, you guys are my heroes, thank you so much!

Andy Oliphant

A&M Design Studios
Copy linkTweet thisAlerts:
@metallibangerauthorDec 10.2003 — One more question, is there a way to have multiple print links on a page, that print different files? Maybe some setup like the download thing Pyro linked to, where the array is numbered?

Andy Oliphant

A&M Design Studios
Copy linkTweet thisAlerts:
@AdamBrillDec 10.2003 — To print files, check out the attached zip file. Right now it is set up so you can type in any file that you want to print it, but you could change it to have different buttons for each file.

For example, if you want to have a button that will print test.txt, it would look like this:

<input type="button" onclick="print_file('test.txt');" value="Print test.txt">

[upl-file uuid=5b5ec648-e603-493f-a7e1-309fd63424c5 size=731B]printfile.zip[/upl-file]
Copy linkTweet thisAlerts:
@metallibangerauthorDec 10.2003 — Also, pyro, how do you impliment php scripts? I've never used php, so what do you do, put the main code in the <head> tags? So far, when I try that, it just tries to go to a page named [b]filedownload.php?index=0[/b] which obviously doesn't exist. Not sure how to do this...

Andy Oliphant

A&M Design Studios
Copy linkTweet thisAlerts:
@pyroDec 10.2003 — First of all, your server needs to support PHP. Most do.

If it does, just take the code that is on the page that I linked to, and save it as download.php. Now, change the items in the array to point to your files, and link to it as shown.
Copy linkTweet thisAlerts:
@metallibangerauthorDec 12.2003 — K, thanks everyone. I ended up using the php script that pyro posted and a java "print onLoad" command that someone gave me on the javascript forum. Works like a charm. The page will be www.jonnywenino.com whenever they get hosting, but for demo purposes it's up [URL=http://www.highdesertcustomwoodworking.com/jonny/index.html]here[/URL] if you guys want to see how I used those little tricks. Thanks again!

Andy Oliphant

A&M Design Studios
×

Success!

Help @metallibanger 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 5.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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