Outils pour capturer et convertir le Web

Convertir des pages Web et HTML en PDF

API Node.js

Lors de la conversion de pages Web et HTML en PDF API Node.js de GrabzIt fournit les fonctionnalités suivantes qui aident intégrener GrabzIt into votre système aussi facilement que possible. Cependant, avant de commencer, rappelez-vous qu'après avoir appelé le url_to_pdf, html_to_pdf or file_to_pdf méthodes le save or save_to méthode doit être appelée pour prendre la capture d'écran PDF ou pour convertir le code HTML directement au format PDF.

Options de base

Un seul paramètre est requis pour convertir une page Web into un document PDF ou à convertir HTML en PDF comme indiqué ci-dessous.

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

Identifiant personnalisé

Vous pouvez transmettre un identifiant personnalisé au PDF Comme indiqué ci-dessous, cette valeur est ensuite renvoyée à votre gestionnaire GrabzIt Node.js. Par exemple, cet identifiant personnalisé pourrait être un identifiant de base de données, permettant d'associer une capture d'écran à un enregistrement de base de données particulier.

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;
    }
});

En-têtes et pieds de page

Lorsque vous créez une capture d'écran PDF, vous pouvez demander que vous souhaitiez appliquer un fichier particulier. modèle au PDF généré. Ce modèle doit être saved à l'avance et spécifiera le contenu de l'en-tête et du pied de page avec toutes les variables spéciales. Dans l'exemple de code ci-dessous, l'utilisateur utilise son modèle appelé "mon modèle".

S'il n'y a pas de marge supérieure ou inférieure suffisamment grande pour l'en-tête ou le pied de page, elle n'apparaîtra pas dans le PDF. Dans l'exemple ci-dessous, nous avons défini les marges supérieure et inférieure sur 20 pour fournir beaucoup d'espace.

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 un élément HTML en PDF

Si vous voulez simplement convertir un élément HTML tel qu'un div ou un span directement into un document PDF que vous pouvez utiliser avec la bibliothèque Node.js de GrabzIt. Vous devez passer le Sélecteur CSS de l'élément HTML que vous souhaitez convertir en targetElement paramètre.

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

Dans cet exemple, nous souhaitons capturer tout le contenu de la plage portant l’id de ArticlePar conséquent, nous passons ceci à GrabzIt comme indiqué ci-dessous.

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;
    }
});

La façon dont un PDF est rogné lors du ciblage d'un élément HTML peut être contrôlé en utilisant ces techniques.