Narzędzia do przechwytywania i konwertowania Internetu

Konwertuj adresy URL i HTML na DOCX

Java API

Dodanie możliwości konwersji HTML lub stron internetowych into Dokumenty Word do aplikacji nigdy nie były łatwiejsze Java API GrabzIt. Jednak zanim zaczniesz, pamiętaj, że po wywołaniu URLToDOCX, HTMLToDOCX or FileToDOCX metody Save or SaveTo 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.

grabzIt.URLToDOCX("https://www.tesla.com");
//Then call the Save or SaveTo method
grabzIt.HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>");
//Then call the Save or SaveTo method
grabzIt.FileToDOCX("example.html");
//Then call the Save or SaveTo method

Niestandardowy identyfikator

Możesz przekazać niestandardowy identyfikator do DOCX metody pokazane poniżej, ta wartość jest następnie zwracana do programu obsługi Java GrabzIt. 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.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setCustomId("123456");

grabzIt.URLToDOCX("https://www.tesla.com", options);
//Then call the Save method
grabzIt.Save("http://www.example.com/handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setCustomId("123456");

grabzIt.HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", options);
//Then call the Save method
grabzIt.Save("http://www.example.com/handler");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setCustomId("123456");

grabzIt.FileToDOCX("example.html", options);
//Then call the Save method
grabzIt.Save("http://www.example.com/handler");

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”.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setTemplateId("my template");

grabzIt.URLToDOCX("https://www.tesla.com", options);
//Then call the Save or SaveTo method
grabzIt.SaveTo("result.docx");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setTemplateId("my template");

grabzIt.HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", options);
//Then call the Save or SaveTo method
grabzIt.SaveTo("result.docx");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setTemplateId("my template");

grabzIt.FileToDOCX("example.html", options);
//Then call the Save or SaveTo method
grabzIt.SaveTo("result.docx");

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 z biblioteką ASP.NET GrabzIt. Musisz zdać Selektor CSS elementu HTML, który chcesz przekonwertować na setTargetElement metoda DOCXOptions class.

...
<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.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

DOCXOptions options = new DOCXOptions();
options.setTargetElement("#Article");

grabzIt.URLToDOCX("http://www.bbc.co.uk/news", options);
//Then call the Save or SaveTo method
grabzIt.SaveTo("result.docx");