Narzędzia do przechwytywania i konwertowania Internetu

Konwertuj adresy URL i HTML na DOCX

Interfejs API Node.js

Dodanie możliwości konwersji HTML lub stron internetowych into Dokumenty Word do aplikacji nigdy nie były łatwiejsze GrabzIt's Node.js API. Jednak zanim zaczniesz, pamiętaj, że po wywołaniu url_to_docx, html_to_docx or file_to_docx metody save or save_to należy wywołać metodę, aby faktycznie utworzyć DOCX.

Podstawowe opcje

Przechwytywanie stron internetowych jako DOCX konwertuje całą stronę internetową into Dokument programu Word, który może składać się z wielu stron. Do konwersji strony internetowej wymagany jest tylko jeden parametr into dokument Word lub przekonwertować HTML na DOCX jak pokazano w poniższych przykładach.

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

Niestandardowy identyfikator

Możesz przekazać niestandardowy identyfikator do DOCX metody pokazane poniżej, ta wartość jest następnie zwracana do modułu obsługi GrabzIt Node.js. Na przykład ten niestandardowy identyfikator może być identyfikatorem bazy danych, umożliwiając powiązanie dokumentu DOCX z określonym rekordem bazy danych.

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

Nagłówki i stopki

Aby dodać nagłówek lub stopkę do dokumentu programu Word, możesz poprosić o zastosowanie określonego szablon do generowanego DOCX. Ten szablon musi być saved z góry i określi zawartość nagłówka i stopki wraz ze specjalnymi zmiennymi. W przykładowym kodzie poniżej użytkownik używa utworzonego szablonu o nazwie „mój szablon”.

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

Konwertuj element HTML na DOCX

Jeśli chcesz bezpośrednio przekonwertować element HTML, taki jak div lub span, bezpośrednio into Dokument programu Word, który możesz, korzystając z biblioteki Node.js firmy GrabzIt. Musisz zdać Selektor CSS elementu HTML, który chcesz przekonwertować na setTargetElement parametr.

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

W tym przykładzie chcemy uchwycić całą zawartość w zakresie, który ma identyfikator Article, dlatego przekazujemy to do interfejsu API GrabzIt, jak pokazano poniżej.

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