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
May
JQuery
? Because if it is with PHP, without leaving the page, it is impossible (unlessAjax
)– Felipe Douradinho
You can. I thought of using angular or jquery. What you suggest?
– Israel Zebulon
Hello, Have you looked at dompdf (https://github.com/dompdf/dompdf) ? You can capture the document and submit it to a php that does the conversion.
– PerryWerneck
I like Jquery (particularly), I replied...I think it’s perfect for you
– Felipe Douradinho
I recommend using iText7 and pdfHTML (the latest add-on for iText7 that handles exactly your use case). Further explanation can be found on our website at http://itextpdf.com/blog/pdfhtml-introduction
– Joris Schellekens
Very simple, I am using this API: https://htmlparapdf.com.br/como-usar-api.cshtml
– Anderson Oliveira