Creating SVG graphics using a server side script (PHP) - 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

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.

Graphic SVG in html

I´m trying to put in my HTML a SVG vector graphic.
This SVG: http://webkunst.comeze.com/graphic.svg
I managed to load it thru like this:
<embed src="images/grafica-2.svg" type="image/svg+xml"/>
the problem is that it just loads the file, but I need that I can modify the percentages of each color. I mean, that I can control thru the html the data of the svg, not just importing the svg "closed".
Is there anyway to do that?
Frameworks like d3.js and Raphaël allow you to create and modify SVGs. There are plenty of examples for each of them.

Extracting portion of the HTML page

Is it possible to extract a portion of a remote HTML page, and print it on another page, using PHP cURL, HTML DOM parser, or any other method, preserve the original formatting styles, images, tabs functioning?
For example, how to extract content of central column (with tabs and formatting, preserve the look of the original text), from http://ru.yahoo.com/?
As far as I understand, the script should process an external CSS, so that returned content has the same look as the original. What would be most appropriate way, if that's possible? If yes, an example would be highly appreciated. I looked several examples, but didn't find any solution for my case.
Well if I had to do it quickly (read: very dirty) I would do is this I think:
Pull the HTML from the remote server using standard PHP
Use the HTML that you stole took from the other site and add your own HTML to it down at the bottom.
Also add your own CSS to hide the html of the other site you don't want to be visible and style your own html.
Fiddle until it look okay enough. However: I think this will break the loading of the external JS files because of the same domain policy.
A nice approach would be this:
Pull the HTML from the remote server using standard PHP
Parse the HTML with some PHP HTML parser and strip out all external CSS and JS files and pull those files as well.
Use XPath to extract the parts that you need.
Create a new HTML document with your own HTML, the parts that you need, new links to your newly downloaded CSS and JS files. Also add your own CSS and JS to style the result.
You know: RSS was invented for this and if they don't provide an rss feed they most likely don't want you to get the content and post it on your own site. :P

Php display contents of pdf

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.

Categories