Given:

HTML code table.

Task:

Get this table as a picture.

Task details:

This table (parsing HTML code from the site) should be displayed as a telegram message. Telegram does not support most HTML tags, including tables. I decided to solve the problem like this: get the table code, convert it into a picture, send a picture of the table.

What he did:

I read en-SO and decided to follow the path HTML-PDF-IMAGE
I found php-lib receiving HTML code of the table at the input and issuing a *.pdf document with it. Even styles can be used (sic!).
The last step is to convert pdf into a picture.

Problem:

On request type

pdf to image php

only tips are given to use some ImageMagick and GhostScript . But, as I understand it, they will not suit me, because I do not have a dedicated server, but simply hosting with php , and these modules should be directly installed in the system.

Question:

So is there any way to get the image from pdf by the non-prog ragging php program or is it not the way I go?

PS

Perhaps it is worth trying another lib at all? ..

  • Perhaps it is worth putting the table code in open access with a secret link, get this link, set a service like screenshotlayer.com on it, delete the table and be happy? Cheyning some big goes to get the picture. Yes, and a normal picture without the render engine will not work. - user207618
  • @Other, it sounds great, but, unfortunately, it is paid, and the monetization of the future bot is a big question ( - Yuriy SPb
  • 100 / month - maybe not enough, but who's stopping to regat another limit after the limit expires? - user207618
  • @Other, as I understand it, 100 on acc for all the time of its existence and after a month it will not be replenished (Well, I am afraid, these 100 times on acc can even go a day, and it is difficult and unethical to automate the creation of new Accs) - YuriySPb
  • one

1 answer 1

Perhaps it is worth putting the table code in open access with a secret link, get this link, set a service like screenshotlayer.com on it, delete the table and be happy?

screenshotlayer.com convenient (API and buns), but paid.
Services like pdfconvertonline.com/webpage-to-png-online.html , web-capture.net free, but you need to do a little more movements to get the picture: generate a request, parse the answer and download the picture.


For example ( pdfconvertonline.com/ ):

  • POST http://s2.pdfconvertonline.com/convert/convert-webpage-win.php
  • Body: websiteurl=google.com&filetype=PNG&source=WEENYSOFT&convert=Convert+Now%21
  • 302 return to something like http://www.pdfconvertonline.com/results.php?name=00i27-mv4a4.png&ser=2 .
  • The code will link to the picture:

     <a rel="nofollow" href="http://s2.pdfconvertonline.com/convert/p3r68-cdx67/00i27-mv4a4.png" target="_new">00i27-mv4a4.png</a> 

Here is the working code from the vehicle that makes the request for the above site with the necessary headings and displays the resulting HTML code of the page, which contains a link to the required PNG. All that remains is to parse the answer to get a link to the image and download it to your server.

 <?php $myCurl = curl_init(); curl_setopt_array($myCurl, array( CURLOPT_URL => 'http://s2.pdfconvertonline.com/convert/convert-webpage-win.php', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTFIELDS => http_build_query(array(websiteurl=>'LINK_TO_HTML_PAGE_WITH_TABLE_IN_IT.html', filetype=>PNG, source=>WEENYSOFT, convert=>Convert+Now%21 )) )); $response = curl_exec($myCurl); curl_close($myCurl); echo $response; 

And again the code from the author of the answer: To parse the answer, use Simple HTML Dom .

 require_once 'simple_html_dom.php'; // Код страницы ответа в $response $dom = str_get_html($response); $link = $dom->find('#item_1 a', 0); // Это ссылка на картинку printf("Your image: <a href='%s'>%s</a>", $link->href, $link->innertext); // $image = file_get_contents($link->href); 
  • And if you don’t use third-party services, but take the screenshot yourself ?? =)) <pre> <code> <? Php $ im = imagegrabscreen (); imagepng ($ im, "myscreenshot.png"); imagedestroy ($ im); ?> </ code> </ pre> - YurikFirst