Strumenti per acquisire e convertire il Web

Converti pagine Web e HTML in PDF

API Python

Quando si convertono pagine Web e HTML in PDF API Python di GrabzIt fornisce le seguenti funzionalità che aiutano integrate GrabzIt into il tuo sistema il più facilmente possibile. Tuttavia, prima di iniziare, ricordare che dopo aver chiamato il URLToPDF, HTMLToPDF or FileToPDF metodi il Save or SaveTo è necessario chiamare il metodo per acquisire lo screenshot PDF.

Opzioni di base

Spesso quando si converte una pagina Web into un documento PDF verranno prodotte molte pagine per rappresentare l'intera pagina web. È richiesto un solo parametro per convertire una pagina Web into documento PDF o a converti HTML in PDF come mostrato negli esempi seguenti.

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

Identificatore personalizzato

È possibile passare un identificatore personalizzato a PDF metodi come mostrato di seguito, questo valore viene quindi restituito al gestore GrabzIt Python. Ad esempio, questo identificatore personalizzato potrebbe essere un identificatore del database, consentendo di associare uno screenshot a un particolare record del database.

from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

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

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.customId = "123456"

grabzIt.URLToPDF("https://www.tesla.com", options)
# Then call the Save method
grabzIt.Save("http://www.example.com/handler.py")
from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

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

options = GrabzItPDFOptions.GrabzItPDFOptions()
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.py")
from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

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

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.customId = "123456"

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

Intestazioni e piè

Quando si crea uno screenshot PDF è possibile richiedere che si desidera applicare un particolare modello al PDF generato. Questo modello deve essere saved in anticipo e specificherà il contenuto dell'intestazione e del piè di pagina insieme a eventuali variabili speciali. Nell'esempio di codice riportato di seguito l'utente utilizza il proprio modello chiamato "modello personale".

Se non è presente un margine superiore o inferiore sufficientemente grande per l'intestazione o il piè di pagina, non verrà visualizzato nel PDF. Nell'esempio seguente abbiamo impostato i margini superiore e inferiore su 20 per fornire molto spazio.

from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

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

options = GrabzItPDFOptions.GrabzItPDFOptions()
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")

Converti l'elemento HTML in PDF

Se vuoi semplicemente convertire direttamente un elemento HTML come div o span into un documento PDF che puoi con la libreria Python di GrabzIt. Devi superare il Selettore CSS dell'elemento HTML che si desidera convertire in targetElement parametro.

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

In questo esempio, desideriamo acquisire tutto il contenuto nell'intervallo di cui ha l'ID Article, quindi lo passiamo a GrabzIt come mostrato di seguito.

from GrabzIt import GrabzItPDFOptions
from GrabzIt import GrabzItClient

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

options = GrabzItPDFOptions.GrabzItPDFOptions()
options.targetElement = "#Article"

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

Come può essere ritagliato un PDF durante il targeting di un elemento HTML controllato usando queste tecniche.