I already make use of the Headless Browser Phantomjs to download COMPLETE WEB pages FAITHFULLY rendered to displayed in the common browser (it interprets JS and CSS) but with it it is also possible to perform a print screen of the desired page of the shape sequinte:
- Create a file with extension . js
- Paste and save the following content:
Command that accesses a given page and saves the contents of it in a . png (but can save as PDF):
var page = require('webpage').create();
page.open('http://stackoverflow.com/', function() {
page.render('stackoverflow.png');
phantom.exit();
});
With it it is also possible to establish the dimensions of the window where the site is displayed (this is useful if you want to see how a responsive site is being rendered) as follows (this setting should be done before the page.open()):
var webPage = require('webpage');
var page = webPage.create();
page.viewportSize = {
width: 480,
height: 800
};
You can call it using the shell_exec command in this way:
$pathToPhantomJS = 'C:\phantomjs-2.0.0-windows\bin\phantomjs';
$pathToJSScript = 'GetPage.js';
$comand = $pathToPhantomJS . ' ' . $pathToJSScript . ' ' . $site;
shell_exec($comand);
Note: step a third variable that represents the site to have its page printada the site is picked up by the vector of args that are passed to the shell.
It is possible to create a CRON JOB to execute the command phantomjs teste.js
at a certain time.
Phantomjs was very useful to me and is very configurable and I could not describe all the possibilities here so I am pasting some links Official and not Official that may be useful:
Download
Link: http://phantomjs.org/download.html
Documentation
Screen Capture: Link
viewportSize: Link
shell_exec (PHP): Link
Since I only have a link and I don’t have the experience to speak, I will just post the link of what I have already been told: http://html2pdf.fr/en/default
– Maniero
@mustache, thanks! I’m testing that one too html2pdf :) but I don’t know much about this library or the native PHP functions for Pdfs, hence the question... _
– Sergio
I’ve used mpdf, and the fpdf, worth taking a look too.
– Brayan
FPDF is very simple and comes with the documentation that helps a lot
– henrique
@Sergio which one you used and why?
– Jorge B.