Captura la captura de pantalla del sitio web y convierte el sitio web en PDF utilizando la máquina de captura de pantalla - Generador de captura de pantalla del sitio web en línea y sitio web a convertidor PDF.
a) Uso del compositor - Administrador de paquetes para PHP
php composer.phar require screenshotmachine/screenshotmachine-phpb) o descargue el código fuente directamente desde Github.com
Primero, debe crear una cuenta gratuita/premium en el sitio web www.screenshotmachine.com. Después del registro, verá la clave de su cliente en su perfil de usuario. También se mantiene aquí una frase secreta. Por favor, use la frase secreta siempre, cuando sus llamadas de API se llaman desde sitios web disponibles públicamente.
Configurar la clave de su cliente y la frase secreta (si es necesario) en el script:
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed Establezca opciones adicionales para satisfacer sus necesidades:
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website screenshot API guide for more details
$ options [ ' dimension ' ] = " 1366x768 " ; // or "1366xfull" for full length screenshot
$ options [ ' device ' ] = " desktop " ;
$ options [ ' format ' ] = " png " ;
$ options [ ' cacheLimit ' ] = " 0 " ;
$ options [ ' delay ' ] = " 200 " ;
$ options [ ' zoom ' ] = " 100 " ;Se puede encontrar más información sobre opciones en la API de captura de captura de captura de nuestro sitio web.
<?php
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed
$ machine = new ScreenshotMachine ( $ customer_key , $ secret_phrase );
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website screenshot API guide for more details
$ options [ ' dimension ' ] = " 1366x768 " ; // or "1366xfull" for full length screenshot
$ options [ ' device ' ] = " desktop " ;
$ options [ ' format ' ] = " png " ;
$ options [ ' cacheLimit ' ] = " 0 " ;
$ options [ ' delay ' ] = " 200 " ;
$ options [ ' zoom ' ] = " 100 " ;
$ api_url = $ machine -> generate_screenshot_api_url ( $ options );
//put link to your html code
echo ' <img src=" ' . $ api_url . ' "> ' . PHP_EOL ; El enlace api_url generado se puede colocar en la etiqueta <img> o usarse en su lógica comercial más adelante.
Si necesita almacenar una captura de pantalla capturada como una imagen, simplemente llame:
<?php
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed
$ machine = new ScreenshotMachine ( $ customer_key , $ secret_phrase );
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website screenshot API guide for more details
$ options [ ' dimension ' ] = " 1366x768 " ; // or "1366xfull" for full length screenshot
$ options [ ' device ' ] = " desktop " ;
$ options [ ' format ' ] = " png " ;
$ options [ ' cacheLimit ' ] = " 0 " ;
$ options [ ' delay ' ] = " 200 " ;
$ options [ ' zoom ' ] = " 100 " ;
$ api_url = $ machine -> generate_screenshot_api_url ( $ options );
//save screenshot as an image
$ output_file = ' output.png ' ;
file_put_contents ( $ output_file , file_get_contents ( $ api_url ));
echo ' Screenshot saved as ' . $ output_file . PHP_EOL ; La captura de pantalla capturada se guardará como archivo output.png en el directorio actual.
Establezca las opciones PDF:
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website to PDF API guide for more details
$ options [ ' paper ' ] = " letter " ;
$ options [ ' orientation ' ] = " portrait " ;
$ options [ ' media ' ] = " print " ;
$ options [ ' bg ' ] = " nobg " ;
$ options [ ' delay ' ] = " 2000 " ;
$ options [ ' scale ' ] = " 50 " ;Se puede encontrar más información sobre opciones en nuestro sitio web a la API PDF.
$ customer_key = " PUT_YOUR_CUSTOMER_KEY_HERE " ;
$ secret_phrase = "" ; //leave secret phrase empty, if not needed
$ machine = new ScreenshotMachine ( $ customer_key , $ secret_phrase );
//mandatory parameter
$ options [ ' url ' ] = " https://www.google.com " ;
// all next parameters are optional, see our website to PDF API guide for more details
$ options [ ' paper ' ] = " letter " ;
$ options [ ' orientation ' ] = " portrait " ;
$ options [ ' media ' ] = " print " ;
$ options [ ' bg ' ] = " nobg " ;
$ options [ ' delay ' ] = " 2000 " ;
$ options [ ' scale ' ] = " 50 " ;
$ pdf_api_url = $ machine -> generate_pdf_api_url ( $ options );
//save PDF file
$ output_file = ' output.pdf ' ;
file_put_contents ( $ output_file , file_get_contents ( $ pdf_api_url ));
echo ' PDF saved as ' . $ output_file . PHP_EOL ; El PDF capturado se guardará como archivo output.pdf en el directorio actual.
La licencia del MIT (MIT)