Ferramentas para capturar e converter a Web

Converta URLs e HTML em DOCX

API do Node.js

Adicionando a capacidade de converter HTML ou páginas da web into Documentos do Word para seu aplicativo nunca foram tão fáceis com API Node.js do GrabzIt. No entanto, antes de começar, lembre-se de que depois de ligar para o url_to_docx, html_to_docx or file_to_docx métodos os save or save_to O método deve ser chamado para realmente criar o DOCX.

Opções Básicas

Capturar páginas da Web como DOCX converte a página da Web inteira into Um documento do Word que pode consistir em muitas páginas. Apenas um parâmetro é necessário para converter uma página da web into um documento do Word ou para converter HTML para DOCX como mostrado nos exemplos abaixo.

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

Identificador Personalizado

Você pode passar um identificador personalizado para o DOCX Como mostrado abaixo, esse valor é retornado ao seu manipulador GrabzIt Node.js. Por exemplo, esse identificador personalizado pode ser um identificador de banco de dados, permitindo que um documento DOCX seja associado a um registro específico do banco de dados.

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

Cabeçalhos e rodapés

Para adicionar um cabeçalho ou rodapé a um documento do Word, você pode solicitar a aplicação de um determinado modelo para o DOCX sendo gerado. Este modelo deve ser saved com antecedência e especificará o conteúdo do cabeçalho e rodapé, juntamente com quaisquer variáveis ​​especiais. No código de exemplo abaixo, o usuário está usando um modelo criado por ele chamado "meu modelo".

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

Converter elemento HTML em DOCX

Se você deseja apenas converter um elemento HTML, como um div ou span, diretamente into Um documento do Word que você pode com a biblioteca Node.js. do GrabzIt. Você deve passar o Seletor CSS do elemento HTML que você deseja converter para o setTargetElement parâmetro.

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

Neste exemplo, queremos capturar todo o conteúdo no período que possui o ID de Article, portanto, passamos isso para a API GrabzIt, como mostrado abaixo.

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