From Google I have found that there are a lot if issues regarding Firefox's built in "Preview option" for PDF's. Workarounds found is to basically disable the PDF viewer and use anther one. Unfortunately from a developers point of view, this is unacceptable as I will be unable to tell users to disable the previewer. I am asking the group am I doing something wrong, which is causing FireFox's Previewer to choke? basic few lines of code I am using to display the pdf is below. Am I missing something with my headers? Please note that the code works on IE and Chrome, as well as firefox if I change the viewer.
<?php
header("Content-type: application/pdf");
echo $fileData;
?>
How the page renders with previewer enabled:
Frankly I can't figure out why we're wasting resources on re-inventing the wheel (ie, trying to replace Adobe Reader extensions); not to mention that so far I have not seen a single "replacement" -- including Chrome, etc. -- that offers the complete page zooom, format and viewing controls. Why don't we spend that energy on solving the print interface issues!! Or the fact that Firefox leaks like a sieve and crashes catastrophically when it mis-handles memory requests. Sure, Chrome leaks too but it does handle memory requests perfectly. For example, Firefox crashes pretty reliably once the Paged memory gets more than 2GB above my 3.5GB system RAM. But Chrome runs happily at 4-5GB Paged memory above that same system RAM and I only restart it because the system slows below usefulness; it is only an old Pentium D after all. Which brings up another point. Years ago we used to make fun of Microsoft for their "bloatware" OS. Well, boys and girls, those same laughs now apply to all your "modern" software. Assembly might be harder but it sure was smaller and quicker.
If the PDF renders Firefox spawning the external Adobe reader and other browsers, then you are doing everything right and the issue is with the PDF.js rendering.
What can you do about it? Best solution is to fix the underlying issue in the PDF that is choking pdf.js -- could be font issue, or a text layer issue, or a few other things. How do you find out what that issue is? Try appending #disableWorker=true to your URL.
For example, open these URL in Firefox with the pdf.js enabled:
http://www.vd.ch/fileadmin/user_upload/organisation/dinf/sm/fichiers_pdf/TP2020_sm_061010.pdf
http://www.xfront.com/URLversusURN.pdf
Notice it gives you the warning or doesn't show up at all? This is expected, bugs have been reported against both these. Now append the debug line:
http://www.vd.ch/fileadmin/user_upload/organisation/dinf/sm/fichiers_pdf/TP2020_sm_061010.pdf#disableWorker=true
http://www.xfront.com/URLversusURN.pdf#disableWorker=true
Either no more error or at least the contents show. Not a magic bullet, and this might not work for you, but now you can follow the debugging guide to figure out what is going on and fix it in the PDF itself.
append #disableFontFace=true to the URL
Looks like a defect in PDF.js (one of hundreds). Since some time Firefox comes with a PDF reader implemented in javascript, which frankly should never have been put into production in the state that it is now.
Feel free to file a new issue for PDF.js, attaching your PDF file.
Related
I read a lot of topics about scripts that compute html and output pdf; I tried lots of them, and I am always disapointed in the results. Lots of them don't consider the external CSS, lots of them can't be executed from shared hosting (need to be installed in some unaccessible places, like DOMPDF), etc. Also, lots of the threads on the question are pretty old (most of them've been asked in 2010).
Question: Is there a simple way to cURL (from a php script) a remote web page and simply save a pdf of the "print" (like in css media print) version of the page, or even a jpeg, or a docx, or anything that "contains" the images and the styling for offline viewing? And more important, can it be free/open source?
All the web browsers do that with no effort. Once on the page, only press ctrl-p and there it goes (almost). Why is it so trivial to find a good script that can do this? Is there a way to emulate a browser, or what...?
Isn't it possible to cURL and force css media print, then take a snapshot of this?
The difficulty to find this seems very strange to me... I feel like it's a quite simple task.
Try to call wkhtmltox from PHP.
wkhtmltox/bin/wkhtmltopdf www.stackoverflow.com stackoverflow.pdf
This PHP library seems to work with wkhtmltox:
http://thejoyofcoding.org/php-wkhtmltox/
This might help:
http://davidbomba.com/php-wkhtmltox/
I am after a jQuery/PHP means of allowing a user to drag and drop files and then via PHP, upload one or more files to a specific directory on a Linux box.
I only have Firefox 3.6 as my base browser but can also move to FFox if need be.
Can use any HTML5 features as long as I'm using Firefox 3.6
Can someone possibly point me to any examples/sites where this process is demonstrated?
I have had a look at http://www.plupload.com/index.php but this does not work in IE6.
As mentioned, would like it to work in FFox only.
Looking for a solution that does this on IE 6 is really, really building a stall for a dead horse IMO.
It may perhaps be possible using some proprietary - and likely commercial - ActiveX or Java plug-in - I'm not sure. But why go through that, when native support is around the corner in HTML 5?
Firefox 3.6 is the one browser that at the moment provides best support for it, so I would recommend to target that for the moment, and other browsers as they catch up in functionality... Whatever you do, I would really not waste time trying to get stuff like this working in IE 6 except if there is a really, really compelling reason why that specific browser has to be supported.
There exists numerous solutions on generating a thumbnail or an image preview of a webpage. Some of these solutions are webs-based like websnapshots, windows libraries such as PHP's imagegrabscreen (only works on windows), and KDE's wkhtml. Many more do exist.
However, I'm looking for a GUI-less solution. Something I can create an API around and link it to php or python.
I'm comfortable with python, php, C, and shell. This is a personal project, so I'm not interested in commercial applications as I'm aware of their existence.
Any ideas?
You can run a web browser or web control within Xvfb, and use something like import to capture it.
I'll never get back the time I wasted on wkhtml and Xvfb, along with the joy of embedding a monolithic binary from google onto my system. You can save yourself a lot of time and headache by abandoning wkhtml2whatever completely and installing phantom.js. Once I did that, I had five lines of shell code and beautiful images in no time.
I had a single problem - using ww instead of www in a url caused the process to fail without meaningful error messages. Eventually I saw the dns lookup problem, and my faith was restored.
But seriously, every other avenue of thumbnailing seemed to be out of date and/or buggy.
phantom.js = it changed my life.
I have a few sites I built for my work, nothing major, mainly just little tools which people can access and use when they're out of the office. I'm not very experienced as a developer but I like to tinker quite a lot and I was wondering if anyone had any clever little tweaks I could do to my sites to make them download faster? We have an office in south america with a poor internet connection who constantly complain my sites take too long to use. So far I have found the following site which was quite useful and the guys in the other office said they'd seen a difference in the service www.dev-explorer.com/articles/apache-optimisation
Anyone kno of any more little bits and pieces I could do?
Any help is much appreciated.
Thanks in advance
John
Look into YSLOW and read the Yahoo Dev blog. You can do a lot by optimizing the front-end.
Limit the number of http requests (css, js, images)
Use mod_deflate in apache to gzip your content
Use a far-future expires header whenever possible
Make your HTML markup as lean as possible
2 things (from YSlow) that will help are a CDN (Content Delivery Network)... and cookie-less servers for static content.
Even if you can just push your images to load off another server you'll be able to load your HTML content faster while image downloading can happen in the background from the other server(s).
Try to have these other servers (for images, CSS, and Scripts) be cookie-less if possible, its a minor saving, but it sounds like you're trying to squeeze every last drop. ;-)
and of course, cache everything except your HTML.
I'd got for yslow, as already said, and better (because is what yslow is based on) the Yahoo Exceptional Performance Team best practices
A few simple tricks:
Firstly, limit yourself to exactly one CSS and one Javascript file. No more. If you have multiple compact them into one (each). Ideally, your Javascript should also be minified. I've been using JSMin for this lately.
There are some more advanced techniques to optimize this further. You set the expires header to far in the future so the browser doesn't download it as often. To push changes you need to change the link to the css/js file though. You can do this with Apache mod_rewrite and a small PHP script.
More on this in What is an elegant way to force browsers to reload cached CSS/JS files?
You can also use the expires trick on images.
Secondly, gzip your constent. Typically all you have to do for this in PHP is start all your scripts wiht:
ob_start('ob_gzhandler');
This turns on output buffering (good idea anyway) and if the browser says that it supports gzip encoding, your script will be gzipped before sending it to the client.
I need to create Snapshots / Thumbshots / Site preview a-site.com.
There are some site as thumbshot.org that meets with I need. But I do not want to use an external service, not to depend on others for my project (What would happen if they close the site?)
For this reason, I am looking for some project to let me do this.
Any idea?
On windows you can use GD's imagegrabwindow() function.
Edit: The help page actually shows you how to grab a screenshot from IE.
There isn't anything in the PHP library to do this - you're looking at setting up an external application (with a queue) to take images, although you can of course use PHP to add items to the queue.
There are a couple of Windows functions in GD that takes screen shots of the computer (webserver - not the client) so perhaps you could write a script in PHP to do this.
Edit: Was thinking of these: imagegrabscreen and imagegrabwindow. I'm not sure they will do what you want however (even in full screen mode Firefox has ablue bar at the top of the screen - not sure about other browsers). However, Pierre has something on these functions if you're interested.
I'd suggest writing an application in another language (I assume .NET has something) to do this for you.
Edit: This page tells you how to do it in C#
There's not much PHP would do for you in this situation. You'd need a complete (X)HTML rendering engine with CSS-support, possibly also with JavaScript support.
That, or use some kind of kinky script that would launch a real browser, and take a screenshot out of that. Either way, PHP is probably not the right tool for the operational part.
There's a Firefox extension that converts the webpage you're viewing to an image:
http://www.screengrab.org/
http://addons.mozilla.org/en-US/firefox/addon/1146
If you're willing to get creative, it might be possible to access this problematically.
Thanks to all.
I found a pseudo-solution, (using dcom + imagegrabscreen + wamp).
I need to resize the final.png with gd, because the png is equal to resolution of client (in my home, is a picture of 1650*1280).
Whe I end this, I will post a .zip file to dowload
Thanks again
(But if anyone have a better idea, I am happy to see that)
PS: Sorry for my english