Добавление возможности конвертировать HTML или веб-страницы into Документы Word для вашего приложения никогда не было проще с GrabzIt's Node.js API, Однако, прежде чем начать, помните, что после вызова url_to_docx, html_to_docx or file_to_docx методы save or save_to метод должен быть вызван для создания DOCX.
Захват веб-страниц как DOCX преобразует всю веб-страницу intДокумент Word, который может состоять из множества страниц. Для преобразования веб-страницы требуется только один параметр intдокумент Word или конвертировать HTML в DOCX как показано в приведенных ниже примерах.
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
Вы можете передать пользовательский идентификатор DOCX методами, как показано ниже, это значение затем возвращается в ваш обработчик GrabzIt Node.js. Например, этот пользовательский идентификатор может быть идентификатором базы данных, позволяя связать документ DOCX с конкретной записью базы данных.
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; } });
Чтобы добавить верхний или нижний колонтитул к документу Word, вы можете запросить, чтобы вы хотели применить определенный шаблон в DOCX генерируется. Этот шаблон должен быть saved заранее и определит содержимое верхнего и нижнего колонтитула вместе с любыми специальными переменными. В приведенном ниже примере кода пользователь использует созданный им шаблон, который называется «мой шаблон».
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; } });
Если вы хотите просто конвертировать HTML-элемент, такой как div или span напрямую intДокумент Word, который вы можете использовать с библиотекой GrabzIt Node.js. Вы должны пройти CSS селектор элемента HTML, который вы хотите преобразовать в setTargetElement
Параметр.
... <span id="Article"> <p>This is the content I am interested in.</p> <img src="myimage.jpg"> </span> ...
В этом примере мы хотим захватить весь контент в диапазоне, который имеет идентификатор Article
поэтому мы передаем это в GrabzIt API, как показано ниже.
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; } });