Reputation: 6007
I want to to convert a HTML table to a PNG or GIF image. I'm using Perl under Linux operating system.
I use the TinyMCE editor. The user can edit a HTML table (using CSS classes and other CSS formatters), and I want to save this table as an image.
What is the simplest way to do this?
Upvotes: 1
Views: 7462
Reputation: 315
Can you use ImageMagick/PerlMagick and Webkit?
https://metacpan.org/module/PDF::WebKit
http://code.google.com/p/wkhtmltopdf/
https://metacpan.org/module/Image::Magick
http://www.imagemagick.org/script/perl-magick.php
use PDF::WebKit;
use Image::Magick;
# PDF::WebKit->new takes the HTML and any options for wkhtmltopdf
# run `wkhtmltopdf --extended-help` for a full list of options
my $kit = PDF::WebKit->new( \$html, page_size => 'Letter' );
push @{ $kit->stylesheets }, "/path/to/css/file";
# save the PDF to a file
my $file = $kit->to_file('/path/to/save/pdf');
#Perl interface
my $p = new Image::Magick;
$p->Read('/path/to/save/pdf');
$p->Write("file.png");
#Or command line
my @args = ( 'convert', '/path/to/save/pdf', "file.png" );
system(@args) == 0
or die "system @args failed: $?";
Upvotes: 1
Reputation: 2063
You can accomplish this with a few command line tools.
$: html2ps table.html > table.ps
$: ps2pdf table.ps
$: convert table.pdf table.png
On my Ubuntu system I installed these with:
apt-get install html2ps
apt-get install ps2pdf
apt-get install imagemagick
The conversion isn't likely to be identical to what you see in your web browser.
Upvotes: 3