PDF Thumbnails in HTML5 - html

Can anyone suggest me how to create a PDF thumbnail which shows a miniature preview of the pdf file in html5. Something similar to the behaviour seen in Gmail while uploading pdf files.
Currently am using embed element, but it gives me unnecessary scrolls and not able to zoom in the file,which works across all browsers. If I set #zoom it works only in chrome.

This can be achieved using https://mozilla.github.io/pdf.js/
If the thumbnails are not compatible in browsers like IE, including compatibility.js from the same library would solve the problem.
We have to create a canvas and use the library utility to get the thumbnail in the canvas.

Related

Some components of an adobe interactive pdf aren't showing as expected

I was given an interactive pdf file, it has a slide with a small slideshow (3 slides) when looked at that particular slide. There is a play button and stop button at the bottom that appears/disappears if you move your mouse over it, and we can choose to play it or stop it. I don't know if its a video though. But, there is some interactivity in that slide. I tried to embed this pdf in an HTML file iframe. It works for the most part but the interactivity doesn't work in chrome: I have Version 53.0.2785.143 m of chrome.
However, not sure if by fluke or what, in IE 11 its working. Any ideas on how this can be made to work on chrome? I am using a simple iframe
<iframe src="file://C:\Users\svboll\embed-pdf\Interactive.pdf"
style="width:718px; height:700px;"
frameborder="0"></iframe>
IE 11 uses the Adobe Reader plugin (if available and it sounds like it is) to display the PDF in the iFrame so you'll see the interactivity play correctly there. Edge doesn't and neither does Chrome. Chrome uses it's own built-in PDF viewer which doesn't support most interactivity. For interactive PDF, you simply will not be able to create a consistent experience of PDF in an iframe across browsers, platforms, and devices. This is not a limitation of PDF, it's a limitation of the viewers in that they have not fully implemented the PDF specification.

Embed PDF in mobile browsers

I have the code below which is a perfect solution to what I need, which would essentially be embedding any of JPG, GIF, PNG or PDF files in my webpages. It works perfectly in PC browsers, but a critical requirement for the pages is to have them compatible in mobile browsers due to its target users.
<iframe src="uploads/test1.pdf" width="auto" height="auto"> </iframe>
Although image files work fine, PDF files are opened separately in the mobile browser and not embedded inline in the web page. What would be an alternative solution or implementation to this?
You can use PDFJs library. Using just JS you can render pdf files.
Please , check here : https://mozilla.github.io/pdf.js/
One simple option is that the the object element provides a fallback, so you can do:
<object data='some.pdf'>
<p>Oops! Your browser doesn't support PDFs!</p>
<p>Download Instead</p>
</object>
Then, when the mobile browser can't get the item, it'll just show this and you'll be all set, kinda.
Here is my solution to this problem.
<object data="mypdf.pdf" type="application/pdf" frameborder="0" width="100%" height="600px" style="padding: 20px;">
<embed src="https://drive.google.com/file/d/1CRFdbp6uBDE-YKJFaqRm4uy9Z4wgMS7H/preview?usp=sharing" width="100%" height="600px"/>
</object>
Explanation:
<object> tag has a feature that when it is unable to load item, it loads the content inside itself i.e tag.
Since object tag cannot load on mobile view, therefore on mobile devices, embed tag will become active.
Q) Why can't we directly use tag for all cases?
You can actually, but since the embed tag is loading file from
drive, it does not gives any user controls for the pdf that we see
with object tag (zoom, page no., etc.). So our code will give the user pdf view controls atleast in the desktop mode instead of not giving any controls at all.
Q) Direct drive links don't work....so why this solution?
In the above google drive URL, view is changed to preview.
drive.google.com/file/d/1CRFdbp6uBDE-YKJFaqRm4uy9Z4wgMS7H/view?usp=sharing
becomes,
drive.google.com/file/d/1CRFdbp6uBDE-YKJFaqRm4uy9Z4wgMS7H/preview?usp=sharing
So, we can make direct drive links work with this little modification
Google Docs viewer offers a feature, that lets you embed PDF files and PowerPoint presentations on a web page.
<iframe src="https://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:100%; height:650px;" frameborder="0"></iframe>
replace the URL(http://infolab.stanford.edu/pub/papers/google.pdf) with your own address, It's worked for me but it takes more time to load on
src:http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html?utm_source=pocket_mylist
The only way I have found, which allows you to embed pdf is using Google drive, then select the menu button once you have opened your file, and select get embed code, you can only use a Google drive or Google docs reference. And you must also turn public sharing on otherwise others won't be able to view it without permission.
Using Adobe PDF Embed API solved my problem.
Adobe PDF Embed API
I ran into the same issue. As a new developer, I wasn't aware that mobile browsers have issues embedding PDF files in iframes. I am now... lol
I racked my resources trying to get this to work when it dawned on me that mobile browsers do not have an issue displaying PNG files in a new window. So, in my infinite wisdom, I opened the PDF files in Gimp 2.0 then exported them as PNG files. And then I created buttons for the user to click and now it opens the graphic instead of trying to embed the PDF.
Looks like this:
<input class="AG" id="UnityBtn" type="button" value="Unity" onclick="location.href='../Meeting_Info/Unity.png'" />
I don't know if this is possible for you, but it worked beautifully for me.
Use an object tag with a iframe tag inside your object tags.
The object data can be a pdf or png file by changing the type and can use any link you want stored wherever, however the I frame is the one which will be loaded for mobiles which has to be a link from Google drive or Google docs you also need to allow the files to be shared public otherwise others won't be able to view them.
I would share the code but this site has some rubbish rules about code and won't let me share them so I'll leave you to Google how object and iframe tags work by viewing better sites that actually wants the help from developers.
Have fun guys!

Change background color in PDF viewer using either embed, object or iframe methods

I've been playing around with different methods of displaying PDFs with the goal of finding a way of changing the grey background to white.
Here is a simple example using object tags (I get the same result with embed and iframe tags):
http://jsfiddle.net/5CALy/7/
HTML
<object data='https://dl.dropboxusercontent.com/u/58922976/test.pdf#view=FitH&scrollbar=0&toolbar=0&statusbar=0&messages=0&navpanes=0'
type='application/pdf'
width='84%'
height='110px'>
<p>It appears your Web browser is not configured to display PDF files.
No worries, just <a href='https://dl.dropboxusercontent.com/u/58922976/test.pdf'>click here to download the PDF file.</a></p>
</object>
Thanks!!
The OP Link actually now succeeds by default, here is the view of requesting no pdf where response is with image on white background
https://dl.dropboxusercontent.com/u/58922976/test.pdf
However it is normal to use a dark or light presentation background for images PowerPoints pdf other viewing
It is entirely up to the viewer
This browser only opens files in external mode
Or why not rainbow friendly?
But for the answer, ask users to do it themselves
For Firefox users there is a hack see How can I enable dark mode when viewing a pdf file in firefox https://stackoverflow.com/a/74564207/10802527
You can but cannot!
I mean,
Every browser (Chrome, Edge, Firefox, Safari, etc.) use their own PDF engine for displaying embedded PDF Files. You can use JavaScript or jQuery to detect the element which has the grey color and change it to white but you'll have to do this for every browser available in the market which is nearly impossible. Moreover, Web Browsers do not provide you an API for this.
The only better solution for this is to make your own PDF Viewer:
You can use this https://mozilla.github.io/pdf.js/ opensource package (By Mozilla) to get it done.
Welcome!

Jpeg, png, gif format images are not displaying in any browser

I am designing a website, I am creating some images for that website by using the illustrator and photoshop software, storing those images in jpeg, png and gif formats. I am writing code for the website in the eclipse software, because I am using jsp and javascript to debug it.
My problem is, the images I have created and linked to the html file are displaying in the Eclipse browser (It is an inbuilt browser to check the code). But, they're not displaying in any other browsers like IE, CROME, FIREFOX.
Can anybody help me?
Thanks in advance.
Off hand, it sounds like you don't have the images linked properly. Aside from checking the code itself, I'd view source in Firefox ( CTRL + U ) and try clicking on the img src urls. If clicking them doesn't load the actual image file, your links are wrong.

Inline PDF viewer

Is there is PDF viewer which I can embed into my HTML and which I can style as I want.
Actually I need to show some page of PDF file and customize my own UI (few buttons to turn over the pages and commenting).
And if there is any Ruby solution (It's not actually about programming, as I understand) it will be great.
I want to show pdf because:
User can copy text
Text is in original layout
So I don't want to show it as images or as a converted text. But I want to show page in simple design. Without Flex or whatever.
Yes, it is possible, with HTML5!
https://github.com/mozilla/pdf.js/
This is a pure-javascript library that uses HTML5 functions to open a PDF file and render it in the page.
I successfully test the library in following browsers:
IE9 and current version of Google Chrome, Firefox, Safari
IE8 and lower do not support pdf.js (lacking HTML5 functions)
Usage
Include the javascript libraries in the HTML file and add an -element ( is HTML5 element, so it will work only in HTML5 browsers):
<body>
<canvas id="the-canvas" style="border:1px solid black;"/>
</body>
Use a javascript call similar to this to render the PDF inside this canvas:
PDFJS.getDocument('your-file-goes-here.pdf').then(function(pdf) {
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
});
Other than a few browsers that have PDF viewers built in (Chrome comes to mind), PDF display is handled by external plugins, over which you have no control. You can't embed a PDF into a page, other than via iframes, and even then it's a completely external app from the browser, and not subject to css styling rules.
I don't see what Ruby has to do with this, as that'd be a server-side operation, and you're talking about client-side preparing. You could use Ruby (or most any other language) to extract the PDF's text, but you explicitly say you don't want to do that.
The closest thing to what you're asking would be Google Doc Viewer. It at least doesn't require anything more than JavaScript.
You could alternatively convert the PDF into HTML5 and display those pages using the PDF2HTML5 product by IDRSolutions. The output can be placed inside your own CMS and you can add your own GUI or you could use the existing options. You can have a look at potential output on the free converter and trial it if you like, it's a 100% Java library though which may or may not be a problem.
Note: For the sake of transparency it's worth mentioning I am currently a developer on said product so am very familiar with it's capabilities.
It's also worth noting pdf.js doesn't always perfectly match the actual pdf but it is very difficult to get an exact match and still preserve some of the key features you want. However it does do quite a good job most of the time.
The only thing that I know of that would help you do that is Adobe Flashpaper (there could be open source alternatives? Not sure).
http://www.adobe.com/products/flashpaper/
Examples here:
http://www.adobe.com/products/flashpaper/examples/
Considering compatibility, the best is to use a genuine adobe software for rendering pdf. Third party renderers work most of the times, but occasionally have trouble with some aspect of formatting. You can just download pdf reader from the adobe website, do a simple setting on the web browser, and let the browser open a pdf file using the genuine pdf renderer. At least on Firefox, you can do that.
If you want to progmatically display a pdf file without using a web browser, that means you need a GUI toolkit that works with a pdf renderer. All I know is poppler on ruby/gnome2. I once was able to use it with ruby 1.8, but since I have moved to ruby 1.9, I have not tried it. Other standard GUI toolkits for ruby are wxruby, fxruby, ruby/qt, shoes etc., but I am not sure which of them has a pdf renderer.
Sorry if not helpful.
No need for external libraries. Much browsers support already multiple ways to vies the pdfs. Like object, iframe, embed. You can use an object, with an iframe fallback, which in return fallbacks on a download:
<object data="/pdf/sample-3pp.pdf#page=2" type="application/pdf" height="100%" width="100%">
<iframe src="/pdf/sample-3pp.pdf#page=2" style="border: none;" height="100%" width="100%">
This browser does not support PDFs. Please download the PDF to view it: Download PDF
</iframe>
</object>
Source