Php display contents of pdf - php

Is it possible to print the contents of a pdf using php ,javascript or jquery

There is a jQuery PDF document viewer based on PDF.js available here:
http://dev.funkynerd.com/projects/jquery-pdfdoc/wiki
It renders the PDF on the client in javascript and so does not require any client-side software other than a relatively modern browser.

No for the JavaScript/jQuery piece, on the PHP side if you're using a library to read the files then that's an option, for your PDF options in PHP check out this question.
If you just want to display the content to the user though, just returning the PDF itself and letting their client-side viewer of choice do the work would be my first option.

Related

PHP or Jquery Library code that outputs a section of a webpage to a PDF file

I need to find and use a PHP or Javascript library or plugin that can output my html code to a pdf. I have seen libraries such as MPDF, FPDF have a number of limitations, for instance the above mentioned libraries dont render svg elements and charts.
I am currently using MPDF to render html tables nicely but I also have charts and maps on my webpage being output dynamically using Jquery and some other svg elements.
Any ideas?
I use external program to render PDF from HTML(used it with PHP and Ruby) called wkhtmltopdf which renders any HTML using WebKit(with styles, scripts etc) and allows you generate output PDF file. Since it support SVG i think that should be displayed in PDF - but better to use more recent versions because there could be some unsupported features in older one.
system('/usr/local/bin/wkhtmltopdf input.html output.pdf');
You of course can control some options like page orientation and size using arguments

How to conver HTML + Javascript to PDF using PHP

I'm trying to convert a HTML page which contains Javascript (that formats certain information after the document is loaded) to PDF, using PHP prefarably.
The javascript code will look something like this:
$(document).ready(function() {
formatProfile();
});
This will format the raw data and replace it to the specific DIV.
However, when I do a render and try to convert it to PDF the DIV remains empty, as if the javascript component is not rendered at all.
I've tried using mpdf, wkhtmltopdf, dompdf and many more but none work as intended. Is there any library that will work or is there any workaround (assuming I still prefer to use the javascript to process and output the results to DIV)?
PhantomJS is probably your best bet here. You'll have to install the software on your server, but it gives a nice implementation of webkit in a headless setup so that you can completely render a page, javascript included and then capture the screen output to a PDF.
EDIT:
You might look at this PHP project which wraps the PhantomJS application in a PHP script for easier web screen capture from within PHP.
You can try this http://www.tcpdf.org/ . Site providing some good examples and also you can design page layout as your own styles. I think this will solve your issues.
PDFreactor 6 can convert HTML to PDF and process the JavaScript. It also provides a PHP wrapper.

Print multiple uploaded document from a web application

I want to know if this is possible to print all attached pdf from an object.
(i'm afraid not, but better asking ;D)
context:
User uploads multiple pdf file in his account, then later, he clicks on "print all the pdf attachements", instead of downloading and then one by one clicking on "print"
Thanks.
There are several ways you can go about this with either just JS or a combination of PHP and js (and perhaps server-side programs that can be called by PHP):
Have the target document be a php file which programatically join all the PDFs into a single document (for instance, with pdftk) and then outputs the joined file with PDF headers. This file would be loaded into an iframe which you could call window.print() on with JavaScript.
Use javascript's window.print() function to target several hidden iframes each of which has one of the PDFs loaded in it. The major drawback of this approach is that it will generate multiple print dialogue boxes.
Both of these approaches rely on the user having the necessary settings and plugins to actually load PDFs within the browser window, but if they don't they'll be prompted to download the large file/multiple files.
This can not be done with PHP. Why? Well, PHP is a server-side script. It has no possibilities to access the user's printer.
To my knowledge there is no solution with javascript either. Mike made a good point with the printer dialog being accessible through a javascript command but that is where it stops. This is a good thing though, would you want a page you enter to be able to use your printer without your permission?
Best way is probably to concatenate all the pdf into a single document server side then allow the user to download and print that. This is what manuscriptcentral and probably other online academic peer review systems do.

Highlighting text on PDF page using JQuery?

I wonder to know how can we hightlight text and make annotations using JQuery ?
If this feature not available with JQuery , Is there possibility to make it with JavaScript ?
Actually, Acrobat reader has a fairly robust API for manipulating .pdf documents ...
... and that API happens to be in Javascript.
Here are a couple of links:
http://www.adobe.com/devnet/acrobat/javascript.html
http://asserttrue.blogspot.com/2010/07/workaround-for-acrobat-javascripts-lack.html
http://www.evermap.com/javascript.asp
Whether any of this will work in your particular scenario is anybody's guess.
'Hope that helps...
It can't be done. JavaScript runs on HTML pages and manipulates the DOM.
PDF files are transferred as binary and are viewed using a PDF viewer plugin. Javascript is nowhere in the process.
I had similar problem and my solution for now is to use Kineticjs to draw on a PDF ( highlights it's just a transparent rectangle ). Then I'm packing everything (all drawing) into Json string and sending it to the server where I'm using PDFsharp to process and save.

Creating SVG graphics using a server side script (PHP)

Is there a way to generate an HTML file using a PHP script which has an SVG embedded where the SVG itself is dynamically generated by the PHP script?
Basically, I want to display a dynamically generated SVG image to a client but <embed>, <object> as well as <iframe> only refer to external sources while PHP generates the current HTML page only (and not the external sources)
Further, is there a Javascript solution possible where I add SVG elements in the current DOM one by one?
Try linking to your php file like this: <object href=svg_generator.php> <!-- other attributes necessary for embedding svg not listed here -->
You can have a look at raphael http://raphaeljs.com/ a wonderful javascript library which make easy to manipulate svg objects in a cross-browser way.
I am sure that it will help you a lot

Categories