Narzędzia do przechwytywania i konwertowania Internetu

Konwertuj adresy URL i HTML na DOCX

API PHP

Dodanie możliwości konwersji HTML lub stron internetowych into Dokumenty Word do aplikacji nigdy nie były łatwiejsze PHP API GrabzIt. Jednak zanim zaczniesz, pamiętaj, że po wywołaniu URLToDOCX, HTMLToDOCX or FileToDOCX metody The 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. W poniższych przykładach PHP konwertuje HTML na DOCX i strona internetowa into dokument Word z tylko jednym wymaganym parametrem.

$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 twojego programu obsługi GrabzIt PHP. 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.

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

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

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

$options = new \GrabzIt\GrabzItDOCXOptions();
$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.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

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

Nagłówki i stopki

Podczas gdy GrabzIt nie obsługuje tradycyjnego szablonu programu Word. Podczas dodawania nagłówków lub stopek do dokumentu programu Word możesz poprosić o zastosowanie 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”.

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

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

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

$options = new \GrabzIt\GrabzItDOCXOptions();
$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");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$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 Worda, który możesz z biblioteką PHP GrabzIt. Musisz zdać Selektor CSS elementu HTML, który chcesz przekonwertować na setTargetElement metoda GrabzItDOCXOptions 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. Przekazując to GrabzIt as, jak pokazano poniżej.

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

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTargetElement("#Article");

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

Nie ma znaczenia, czy konwertujesz adres URL na Word, jak pokazano w przykładzie, czy HTML na Word. Oba elementy docelowe HTML są dokładnie w ten sam sposób.