Outils pour capturer et convertir le Web

Convertir les URL et HTML en DOCX

API Node.js

Ajout de la possibilité de convertir du HTML ou des pages Web into Les documents Word de votre application n’ont jamais été aussi simples avec API Node.js de GrabzIt. Cependant, avant de commencer, rappelez-vous qu'après avoir appelé le url_to_docx, html_to_docx or file_to_docx méthodes le save or save_to La méthode doit être appelée pour créer le fichier DOCX.

Options de base

La capture de pages Web au format DOCX convertit la page Web entière into un document Word pouvant comporter plusieurs pages. Un seul paramètre est requis pour convertir une page Web into un document Word ou à convertir HTML en DOCX comme indiqué dans les exemples ci-dessous.

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

Identifiant personnalisé

Vous pouvez transmettre un identifiant personnalisé au DOCX 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 un document DOCX à 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_docx("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_docx("<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_docx("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

Pour ajouter un en-tête ou un pied de page à un document Word, vous pouvez demander à appliquer un programme particulier. modèle au DOCX en cours de génération. 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 un modèle qu'ils ont créé, appelé "mon modèle".

var grabzit = require('grabzit');

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

var options = {"templateId":"my template"};

client.url_to_docx("https://www.tesla.com", options);
//Then call the save or save_to method
client.save_to("result.docx", 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 = {"templateId":"my template"};

client.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options);
//Then call the save or save_to method
client.save_to("result.docx", 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 = {"templateId":"my template"};

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

Convertir un élément HTML en DOCX

Si vous voulez simplement convertir un élément HTML tel qu'un div ou un span directement into Un document Word 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 setTargetElement 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 transmettons cela à l'API 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");

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