drawing flow chart using php - php

I want to dynamically create a visual flow chart using php on web.
I tried to use iMagick extension to draw rectangles, lines, and etc.
However, I ran into a problem that all the drawings have to be on an image and that makes my html code not appear on screen.
So I searched if there is a flow chart extension or functions I can use which I failed.
Is there any flow chart making library/application that I can use with php to dynamically draw flow chart on web?
If not, is there a way to have plain html texts above the image I created with iMagick extension so I can see my html texts positioned at the same spot as the rectangles I made using iMagick?

What is generally done is you have two files, one with the page contents, and the other that is the image, then you embed the image like you would a regular image (<img> tags).
Say you have index.php which is your main page, and you have image.php that has your flowchart code. On index.php you embed the image like this:
<img src="image.php" alt="flowchart" />

Related

How would I draw a rectangle in PHP, and then convert to a .pdf file?

I'm just wondering about a small problem I have. I'm creating a simple website with PHP, HTML and CSS. The user enters the dimensions of a rectangle into a form, and this all works perfectly. However, I'm unsure how to proceed.
The system should then use these dimensions (both stored as separate variables) to draw a rectangle of that size (in cm). The rectangle should be draw in a .pdf document, which the user can then download.
I'm a beginner, so sorry if there's anything wrong with this question.
You're going to want to start with looking into the html5 canvas element for drawing. There's plenty of tutorials online for you. As far as saving to pdf, see this: Convert canvas to PDF good luck.
Take a look at the fpdf extension available for php. Or even better and more consequent: use its unicode capable variant 'tfpdf'.
It allows you to generate a pdf document on the server side in a step by step way. You can control all details of that document. When finished you can return the document to the requesting client.

Library to create print-ready charts in PDF using PHP 5.3

I have to create some nicely formatted charts (bar and 3D pie) from dynamic data using PHP 5.3 and for output as PDF report. The report is not to be rendered to the screen at all. I have made the charts using pChart2 as .png files and imported them using tcpdf. The system works, but the quality level is poor, rendering text as a graphic causes the font edges to be blurry etc. when printed. I tweaked the image size of the .PNG output, and it made some improvements but it increases the file size, and the text still looks blurry.
So what I am after is a library to create charts using PHP that can be exported to .svg or .eps format, so elements are drawn by the printer and render sharply for print. Using TCPDF I have imported our logos that are in .EPS format, and the difference between the images is quite marked.
I have seen there is a library called ezcomponents that i can give a try. But before I dive in, is there any advice on what to try before proceeding?
I have had reasonable success rendering the images on a canvas that is two to three times larger than what I ultimately need and then, once I'm finished, using the imagecopyrresampled() function to copy the large image onto a canvas with smaller dimensions, which I save as a png and add to the PDF file. The dithering is pretty good and curved lines, in particular, benefit greatly from this approach. Text might not benefit quite as much, but its worth trying, because it should require very few changes to your code to experiment with this approach.

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.

Can I make html table into image to embed into pdf

I have been reading about this but I have to do some thing. I have a table with diagonal text in the heading columns and horizontal text in the rows. I was able to make text diagonal using CSS rotation thing, table data is coming from db and I want to generate the same html into the pdf. I don't know who to write diagonal text in the pdf. The solution is to create an image of the visible html table with data and then store it and then make pdf and embed that image there. I have been reading the GD library but how can I make table in GD library I am stuck , Stack Overflow is the last resort. Please help.
try this ezpdf class http://www.ros.co.nz/pdf/readme.pdf. they got some sample code to rotate text and how to embed image into pdf.
example
for ($angle=0;$angle<360;$angle=$angle+20){
$r=rand(0,100)/100;
$g=rand(0,100)/100;
$b=rand(0,100)/100;
$pdf->setColor($r,$g,$b);
$pdf->addText(300+cos(deg2rad($angle))*40,300-
sin(deg2rad($angle))*40,20,$demotext,$angle);
{
$pdf->stream();
If you want to go directly from your HTML code to PDF, and if you need something entirely in PHP you can try dompdf. The 0.6.0 release will include CSS transform support.
For image generation in PHP you can use GD functions (fast) or iMagick (not so wide spread, docs are WorkInProgress, but you could do almost anything you can imagine with it).
GD should be enough.
A simple idea about making text diagonal would be to just rotate the image, once you output text from the db onto it.
Use wkhtmltoimage or wkhtmltopdf.
Do you need to do this only once or does this need to be an ondemand service? If not why not just load the html page take a screenshot and crop it down to the table?
Instead of trying to convert HTML directly to a PDF document, you might want to try a PDF library for creating the document directly in PHP. This way you will get more control over what the PDF looks like, and it may be a better solution that trying to convert your HTML output.
https://stackoverflow.com/questions/560583/which-is-the-best-pdf-library-for-php

creation of pie and bar charts in php website

HI. I wanted to know if we could create pie and bar charts based on info from the database on a php website. I want to grab some information from the database and show it as an image so better analysis. Is there anyway to do this?
Also, If i am using fpdf to generate pdfs from php and mysql, can i also design pie charts in that pdf and show it as an image in that?
You could use the Google Chart API
I'd recommend using tcpdf instead of fpdf. fpdf was pretty good, but is no longer actively developed. tcpdf is.
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
As for the graphs there are many libraries displaying image graphs like http://jpgraph.net/
or client side JS libraries that will create flash graphs like ExtJS
JpGraph is a pure php library for generating graphs which outputs an image. I'm not familiar with fpdf but if it can embed images then this solution should work out.
http://jpgraph.net/
I'm using ChartDirector (not free) and FPDF to do this (today as a matter of fact).
ChartDirector can write the chart to a file, which I stick in /tmp. Then I import the file into the PDF file. Then I delete the file from the disk. Then I do it twenty more times with different data.
I'm sure any chart library that can write to disk will work. With FPDF, you can set the size of the image you import. So here's a trick: create the chart image twice as large as you need it and tell FPDF to place it at the size you want. This way, you'll get an image in the PDF file at around 144 dpi (assuming your library exports at 72dpi for the screen). You'll have a PDF that doesn't look as pixelated when zoomed in, and it will print better.
Check out this article on A List Apart for a method using the Raphael javascript graphics library. It demonstrates how to take a generic HTML table and replace it with a cross-browser, dynamic, scalable pie chart. The same could probably be done for a bar chart.
The advantage of this method is semantically correct markup - useful for users without JavaScript, as well as bots and screen readers.

Categories