Herramientas para capturar y convertir la web

Convierta páginas web y HTML a PDF

API Node.js

Al convertir páginas web y HTML a PDF GrabzIt's Node.js API proporciona las siguientes características que ayudan integrate GrabzIt into su sistema tan fácilmente como sea posible. Sin embargo, antes de comenzar, recuerde que después de llamar al url_to_pdf, html_to_pdf or file_to_pdf métodos de save or save_to Se debe llamar al método para tomar la captura de pantalla en PDF o para convertir HTML directamente a PDF.

Opciones basicas

Solo se requiere un parámetro para convertir una página web into un documento PDF o para convertir HTML a PDF como se muestra a continuación.

client.url_to_pdf("https://www.tesla.com");
//Then call the save or save_to method
client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>");
//Then call the save or save_to method
client.file_to_pdf("example.html");
//Then call the save or save_to method

Identificador personalizado

Puede pasar un identificador personalizado a (PDF) métodos como se muestra a continuación, este valor se devuelve a su controlador GrabzIt Node.js. Por ejemplo, este identificador personalizado podría ser un identificador de base de datos, lo que permite asociar una captura de pantalla con un registro de base de datos particular.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

var options = {"customId":123456};

client.url_to_pdf("https://www.tesla.com", options);
//Then call the save method
client.save("http://www.example.com/handler", function (error, id){
    if (error != null){
        throw error;
    }
});
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

var options = {"customId":123456};

client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>", options);
//Then call the save method
client.save("http://www.example.com/handler", function (error, id){
    if (error != null){
        throw error;
    }
});
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

var options = {"customId":123456};

client.file_to_pdf("example.html", options);
//Then call the save method
client.save("http://www.example.com/handler", function (error, id){
    if (error != null){
        throw error;
    }
});

Encabezados y pies de página

Cuando crea una captura de pantalla en PDF, puede solicitar que desee aplicar un determinado plantilla al PDF generado. Esta plantilla debe ser saved de antemano y especificará el contenido del encabezado y pie de página junto con cualquier variable especial. En el siguiente código de ejemplo, el usuario está usando su plantilla llamada "mi plantilla".

Si no hay un margen superior o inferior lo suficientemente grande para el encabezado o pie de página respectivamente, no aparecerá en el PDF. En el siguiente ejemplo, hemos establecido los márgenes superior e inferior en 20 para proporcionar mucho espacio.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

var options = {"marginTop":20,"marginBottom":20,"templateId":"my template"};

client.url_to_pdf("https://www.tesla.com", options);
//Then call the save or save_to method
client.save_to("result.pdf", function (error, id){
    //this callback is called once the capture is downloaded
    if (error != null){
        throw error;
    }
});
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

var options = {"marginTop":20,"marginBottom":20,"templateId":"my template"};

client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>", options);
//Then call the save or save_to method
client.save_to("result.pdf", function (error, id){
    //this callback is called once the capture is downloaded
    if (error != null){
        throw error;
    }
});
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

var options = {"marginTop":20,"marginBottom":20,"templateId":"my template"};

client.file_to_pdf("example.html", options);
//Then call the save or save_to method
client.save_to("result.pdf", function (error, id){
    //this callback is called once the capture is downloaded
    if (error != null){
        throw error;
    }
});

Convertir elemento HTML a PDF

Si solo desea convertir un elemento HTML como un div o span directamente into un documento PDF que puede con la biblioteca GrabzIt's Node.js. Debes pasar el Selector de CSS del elemento HTML que desea convertir a targetElement parámetro.

...
<span id="Article">
<p>This is the content I am interested in.</p>
<img src="myimage.jpg">
</span>
...

En este ejemplo, deseamos capturar todo el contenido en el lapso que tiene la identificación de Article, por lo tanto, pasamos esto a GrabzIt como se muestra a continuación.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");

grabzIt.url_to_pdf("http://www.bbc.co.uk/news", {"targetElement":"#Article"});
//Then call the save or save_to method
client.save_to("result.pdf", function (error, id){
    //this callback is called once the capture is downloaded
    if (error != null){
        throw error;
    }
});

Cómo se puede recortar un PDF al apuntar a un elemento HTML puede ser controlado utilizando estas técnicas.