Outils pour capturer et convertir le Web

Convertir des pages Web et HTML en PDF

API Perl

API Perl de GrabzIt fournit les fonctionnalités suivantes pour faciliter la création de captures d'écran PDF et la conversion de code HTML directement au format PDF intgriser into votre application. Cependant, avant de commencer, rappelez-vous qu'après avoir appelé le URLToPDF, HTMLToPDF or FileToPDF méthodes le Save or SaveTo méthode doit être appelée pour créer réellement le PDF.

Options de base

Lorsqu'une page Web est convertie into PDF la totalité de la page Web est capturée, ce qui peut générer un document PDF de plusieurs pages. Un seul paramètre est requis pour convertir une page Web into un document PDF ou à convertir HTML en PDF comme indiqué dans les exemples ci-dessous.

$grabzIt->URLToPDF("https://www.tesla.com");
# Then call the Save or SaveTo method
$grabzIt->HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>");
# Then call the Save or SaveTo method
$grabzIt->FileToPDF("example.html");
# Then call the Save or SaveTo method

Identifiant personnalisé

Vous pouvez transmettre un identifiant personnalisé au PDF Comme indiqué ci-dessous, cette valeur est ensuite renvoyée à votre gestionnaire GrabzIt Perl. Par exemple, cet identifiant personnalisé pourrait être un identifiant de base de données, permettant d'associer une capture d'écran à un enregistrement de base de données particulier.

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

$options = GrabzItPDFOptions->new();
$options->customId("123456");

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

$options = GrabzItPDFOptions->new();
$options->customId("123456");

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

$options = GrabzItPDFOptions->new();
$options->customId("123456");

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

En-têtes et pieds de page

Lorsque vous créez une capture d'écran PDF, vous pouvez demander que vous souhaitiez appliquer un fichier particulier. modèle au PDF généré. Ce modèle doit être saved à l'avance et spécifiera le contenu de l'en-tête et du pied de page avec toutes les variables spéciales. Dans l'exemple de code ci-dessous, l'utilisateur utilise son modèle appelé "mon modèle".

S'il n'y a pas de marge supérieure ou inférieure suffisamment grande pour l'en-tête ou le pied de page, elle n'apparaîtra pas dans le PDF. Dans l'exemple ci-dessous, nous avons défini les marges supérieure et inférieure sur 20 pour fournir beaucoup d'espace.

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

$options = GrabzItPDFOptions->new();
$options->marginTop(20);
$options->marginBottom(20);
$options->templateId("my template");

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

$options = GrabzItPDFOptions->new();
$options->marginTop(20);
$options->marginBottom(20);
$options->templateId("my template");

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

$options = GrabzItPDFOptions->new();
$options->marginTop(20);
$options->marginBottom(20);
$options->templateId("my template");

$grabzIt->FileToPDF("example.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.pdf");

Convertir un élément HTML en PDF

Si vous voulez simplement convertir un élément HTML tel qu'un div ou un span directement into un document PDF que vous pouvez utiliser avec la bibliothèque Perl de GrabzIt. Vous devez passer le Sélecteur CSS de l'élément HTML que vous souhaitez convertir en targetElement méthode.

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

Dans cet exemple, nous souhaitons capturer tout le contenu de la plage portant l’id de ArticlePar conséquent, nous passons ceci à GrabzIt comme indiqué ci-dessous.

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

$options = GrabzItPDFOptions->new();
$options->targetElement("#Article");

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

La façon dont un PDF est rogné lors du ciblage d'un élément HTML peut être contrôlé en utilisant ces techniques.