Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Javascript PDF preview

javascript pdf

Best Answer WingedPanther73, 25 March 2014 - 09:42 AM

Okay, I did a search for "javascript read browser settings" on duckduckgo, and it does NOT look promising. The simple ability to read the LANGUAGE in the browser's settings is nearly impossible without calling a server and pulling it from the headers on the request.

 

Worse, each browser holds those settings in a different place, making things more complicated. Ultimately, however, is the security concern. If javascript can READ those settings, it could also probably CHANGE those settings, allowing malicious JavaScript to weaken browser security and then send you to a truly malicious site. ActiveX can do what you want, if you're willing to count on users having access to a Windows computer AND using IE.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts

Posted 25 March 2014 - 07:58 AM

Hello,

 

To display pdf in a browser, I'm using this script http://jquery.malsup...media/misc.html

It work fine for most people.

But if your browser setting is set to download a pdf, each time someone will go to this page, it will download it, and open it in a normal adobe reader window.

This can be kind of annoying.

I try to change the content-type of the browser set to "unknow", but the browser still open it as a pdf

Do you have an idea how to force to display it inline, or maybe a way to detect the browser preference so I won't display it at all?


You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !


#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 25 March 2014 - 08:19 AM

This is exactly why I encourage people not to get too clever with stuff like this. Before researching a way to detect the behavior, I'd start by asking this:

 

1) Why is it important that it display on the page?

2) Is it more important that it display on the page, or that the user get the document?

3) If the user doesn't HAVE a way to view the PDF in the browser (for example, having an alternative PDF viewer that doesn't support in-browser display), do you just want to block access for those users entirely?

 

I'm thinking about scenarios like users of Kubuntu or Lubuntu that use Konqueror or some other light-weight browser for display of websites, and use a non-Adobe PDF viewer. Do you really want to tell a poweruser, "you have to install Firefox/Iceweasel and Adobe's browser and have a certain configuration just so you can see my document"? There's a chance they'll just say "Screw it, I'll look somewhere else."


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts

Posted 25 March 2014 - 08:32 AM

Sadly I don't have an other option.

Since it's the user who upload a document, and can be either a image or a pdf.

If it's a image, there is no problem (quite easy), but when it's a pdf, I don't have any controls about it

The document in question is a legal document, it has to be upload in complete, so I can't do a form where the user could simply re-enter the information (that would be illegal in this senario)

 

On the same page I do have a download option, but it is a lots easier and fast if the user can directly read the document inside the browser.


You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !


#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 25 March 2014 - 09:42 AM   Best Answer

Okay, I did a search for "javascript read browser settings" on duckduckgo, and it does NOT look promising. The simple ability to read the LANGUAGE in the browser's settings is nearly impossible without calling a server and pulling it from the headers on the request.

 

Worse, each browser holds those settings in a different place, making things more complicated. Ultimately, however, is the security concern. If javascript can READ those settings, it could also probably CHANGE those settings, allowing malicious JavaScript to weaken browser security and then send you to a truly malicious site. ActiveX can do what you want, if you're willing to count on users having access to a Windows computer AND using IE.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts

Posted 25 March 2014 - 10:14 AM

Thanks for your help

You confirmed what I tought, it will be almost impossible do to.

For now, I'm gonna leave it like this, a other idea that came in mind was to transform my pdf into a image, I'm gonna have to make some tests on how much quality I am loosing with this


You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !


#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 25 March 2014 - 11:42 AM

One idea I had was to convert the PDF to HTML, and display that to the user. Not sure how easy that would be to do, though.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts

Posted 26 March 2014 - 12:17 AM

The jquery library code is available on github and not even so big. Won't you be able to instead of letting the user press a link, cause that to be a button press to do an ajax call and feed  the response of that to the JS code manually?

 

I'm thinking of replacing

opts.src = opts.src || $el.attr('href') || $el.attr('src') || 'unknown';

with the response of that Ajax call getting the pdf.

Not sure if it works like that, but who knows. Can't even remember is Javascript has something to download files the way I'm thinking.


Edited by wim DC, 26 March 2014 - 12:31 AM.





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download