Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-26-2012, 09:33 AM   PM User | #1
rizmaverick
New to the CF scene

 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
rizmaverick is an unknown quantity at this point
Creating a file in Javascript using the available Bytestream

Is there any way to create a file (eg: a Pdf) in Javascript by setting its mime type,title, content, etc and display it in the browser with the option to download?

I have a Base64 bytestream of a pdf in the javascript and I am using it to display the pdf to the user by:

document.location.href = 'data:application/pdf;base64,' +data;
which opens the file in a new window (it works in all browsers except IE as it has url restrictions) and the file is not downloadable in all browsers. IE is the primary browser for testing my application so this is a big issue.

Option of using a backend technology like Java to create a file and send it as the response is ruled out as I have an ABAP backend and it can give me only the bytestream. Many suggested using jsPdf but jsPdf creates the content from javascript (like setting line by line info and formatting) and uses it. But as I already have all the data and formatting I need I am not able to use it.

Here is the question I asked in stackoverflow for byte conversion and display of pdf in the webpage, that got answered, for additional info:

http://stackoverflow.com/questions/1...tual-bytestrea

I have done my best in searching for the solution but couldn't able to find one yet. Please help. I will be thankful.
Regards, Riswan
rizmaverick is offline   Reply With Quote
Old 06-26-2012, 10:13 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
JavaScript running in the browser has very limited file access - cookies and localStorage only and not separate files. Only when you run JavaScript outside the browser (on the server or on the desktop) is file access permitted.

This block is deliberate for security reasons - otherwise JavaScript could be used to trash your computer.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-26-2012, 07:12 PM   PM User | #3
nicholagi
New to the CF scene

 
Join Date: Jun 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
nicholagi is an unknown quantity at this point
I have a Base64 bytestream of a pdf in the javascript and I am using it to display the pdf to the user by:

document.location.href = 'data:application/pdf;base64,' +data;

which opens the file in a new window (it works in all browsers except IE as it has url restrictions) and the file is not downloadable in all browsers. IE is the primary browser for testing my application so this is a big issue.

Option of using a backend technology like Java to create a file and send it as the response is ruled out as I have an ABAP backend and it can give me only the bytestream. Many suggested using jsPdf but jsPdf creates the content from javascript (like setting line by line info and formatting) and uses it. But as I already have all the data and formatting I need I am not able to use it.
nicholagi is offline   Reply With Quote
Old 06-26-2012, 08:28 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
use the save button inside the pdf viewer to save...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, pdf

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:06 PM.


Advertisement
Log in to turn off these ads.