Highlighting text on PDF page using JQuery? - php

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.

Related

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.

Pdf book reader in php?

Actually I have to upload pdf files and need to read on my website as book reader like a presentation. Please show me the possible ways to achieve my goals.
Thank you
I've been using flexpaper, I use pdf2swf to convert the pdf to swf as I used the flash version but there is a javascript version too.
One possible solution would be to use scribd. You simply upload your document to their website and embed their reader on your website. This is the easiest way, and you get things like searchability. Their reader also works like Adobe's Acrobat Reader.
The downside is that you are uploading your documents onto a public website, so everyone will be able to view it. Perhaps they might have settings where you can lock your documents so that only certain people can see them.
The next solution is to roll your own. You can use turn.js. In this case, you will need to find a way to convert your PDF files to HTML files or perhaps image files. With images, your text won't be selectable, and they won't be discoverable by search engines. Again, converting PDF to HTML can also be difficult as you might lose formatting in the process.
But it is entirely up to your use case. Personally, I would go with scribd, as their platform works very well, and you won't have to worry about implementing your own system.

Programmatically create image from web-page or a single DIV

Is there any way to programmatically create (client or server side (PHP)) a image from a specific DIV or a complete (web) page? I'm currently creating a web-site for free coupons and the idea is when the end-user clicks on the "Print" button, the app opens a new tab/window with all the selected coupons as a single image (JPG, PNG or etc..) in A4 format ready for printing. Each coupons has it's own data (Article name, price, description etc..) so I need it to be done programmatically over a coupon-template I designed.
I do not ask you to write code for me, just to suggest a solution I could use/develop. If not already exist, I will upload/publish it for free :)
Update: I did it with the PHP GD library :) Still not satisfied with the idea to use Images instead of PDF, because each printing results with different Coupon sizes (images) on different PC's. That's why PDF may would be a better solution. You can see/test it on demo.svikuponi.ba - Just select a few Coupons and click the PRINTAJ button above.
You cannot create image from div for sure but yes you can create dynamic images in php using its gd library.
Following links will help:
http://php.net/manual/en/function.imagecreate.php
http://phptutorial.info/learn/create_images/
Here is a great way for you to create images on the client side: http://smus.com/screen-capture-for-chrome-os
You can take this and create a web app that will work nicely on webkit (for other browsers - I'll look at JS polyfills).
Did anyone mention html2canvas and/or jsfeedback ?
It create a page screenshot completely in javascript, then you can send to the server via ajax..
Obviously, CSS support lack some things.
In php, there is many image related functions like imagettftext() in GD library
for details, check this out http://php.net/manual/en/book.image.php
if GD is not enough, you can try imagick as well
for the template, you can try creating a true color handle in php from your file(image) and add the text part or something else with all kinds of effects and bar codes etc.
but in your case, i would suggest dynamic PDF creation since it would better with formatting instead of plain image, the pdf lib :
http://www.fpdf.org/
you could easily have a background image of your token/voucher and overlay the text using some php variables.
i believe it is possible to create a unique bar-code with php imaging too.
It is possible to get a screenshot from a webpage, but this is quite a hassle. You need to start a webbrowser to render the page and get a screenshot from that.
You are probably better of by parsing some specification and feeding it to a couple of GD or Imagick functions. This is less versatile, but easier to manage.

Is there a way to convert a VML document to a bitmap image?

I've been looking for a long time for a way to have a bitmap from a VML document.
In fact, I working on a few libs that use the tag, so I have no problem for anything except for IE (of course) because I'm using ExCanvas in IE, but I'd like to have a bitmap from the generated "canvas" (which is in fact VML).
I've been looking for a few ways to get a bitmap in JS from the VML, but I abandoned this idea, now I'd like to find a server side lib that is able to get a VML string and convert it to a bitmap image. My preferred language is PHP, but if there aren't any in this language, it'll be OK.
I also looked at a Java applet that could do that, but this is in fact impossible without a signed one, this is not possible.
Thank you for your reply !
You could use something like CutyCapt to allow the browser to render it and capture that to an image.
I found a library which looks like the best solution to my problem : VectorConverter.
It has however a few problems :
it only supports a very limited part of the spec
it is not maintained anymore
the code is not very well written and it doesn't use an existing DOM parser for the VML
I don't have time to enhance it !
So if anyone with a lot of time and who is interested in this project is welcome to work on it, and maybe fork it. Contact me if you plan to work on it, I may help you.
The simple possibility is to use C# to display a window loading the vml page in ie webbrowser control and use this.webBrowser.Navigate("file.html") to load the vml page included in the html
and then make a snap shot by capturing the image automatically by using graphic.CopyFromScreen function

Direct Print webpage in PDF file

In my site i m fetching my mysql data by using PHP. I want open that data in pdf file when i click pdf print button is it possible?
First of all, if you want a high quality professional product to do that. You want Prince XML
If you are looking into some open source tool to achieve something similar. You can look into this SO question.
You could prepare static PDF form file, that just fill it in with values using PHP's FDF module.
It depends which platform are you using. This would be an easy job if you are using Groovy on grails. There are plugins which facilitate pdf reporting like the jasper-plugin.
Luis
Check out jsPDF, an open-source library for generating PDF documents using nothing but JavaScript.
You can process the data with Apache FOP after transforming it to XML. (http://xmlgraphics.apache.org/fop/).
If your page is template based, you may create a template which produces xml output and process that. You'll have extremely well contol over the pdf construction. The tradeoff is that it is not a "plug this in and will work" solution, but I've done that and once its set up, works like charm.
I've used TCPDF in the past, it's a little kludgy but can definitely get the job done. (http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf)
The FPDF module in PHP is simple enough to get the data together. It is a safe option since you know what data you are passing out to the PDF engine. There are some streaming pdf options which can take in a bunch of html and then output that to pdf however they can get it quite wrong without you knowing.
I used, on Linux machines, WKHTMLTOIMAGE/WKHTMLTOPDF a number of times, on many projects. It workes like a charm, easy to use, just a script that you run.

Categories