in google cloud installare wkhtmltopdf
- User
in google cloud installare wkhtmltopdf
- Assistant
- User
- Assistant
in google cloud installare wkhtmltopdf
L'installazione di wkhtmltopdf su una macchina virtuale di Google Cloud può essere eseguita seguendo i passaggi sottostanti. wkhtmltopdf è uno strumento da riga di comando che consente di convertire pagine HTML in PDF utilizzando il motore di rendering Webkit.
Connettiti alla tua VM:
Aggiorna il tuo sistema: È sempre una buona pratica assicurarsi che il sistema operativo sia aggiornato prima di installare nuovi pacchetti.
sudo apt-get update
sudo apt-get upgrade
Installa le dipendenze necessarie:
$ sudo apt-get install -y software-properties-common wget
Aggiungi il repository di wkhtmltopdf ed installa la versione desiderata:
Puoi scaricare l'ultima versione stabile di wkhtmltopdf direttamente dal sito ufficiale.
# Scarica l'ultima versione stabile di `wkhtmltopdf`
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
# Installa il pacchetto deb
sudo apt-get install -f ./wkhtmltox_0.12.6-1.bionic_amd64.deb
Verifica l'installazione:
Per assicurarti che wkhtmltopdf sia stato installato correttamente, puoi eseguire il comando:
wkhtmltopdf --version
Dovrebbe restituire la versione installata di wkhtmltopdf.
Utilizzo di wkhtmltopdf:
Una volta installato wkhtmltopdf, puoi utilizzarlo per convertire file HTML in PDF.
wkhtmltopdf input.html output.pdf
sudo.Questo è tutto! Ora dovresti essere in grado di utilizzare wkhtmltopdf sulla tua macchina virtuale Google Cloud.
Welcome to Cloud Shell! Type "help" to get started. To set your Cloud Platform project in this session use “gcloud config set project [PROJECT_ID]” accardo_cloud@cloudshell:~$ sudo apt-get install -y software-properties-common wget
You are running apt-get inside of Cloud Shell. Note that your Cloud Shell
machine is ephemeral and no system-wide change will persist beyond session end.
To suppress this warning, create an empty ~/.cloudshell/no-apt-get-warning file. The command will automatically proceed in 5 seconds or on any key.
Visit https://cloud.google.com/shell/help for more information.
Reading package lists... Done Building dependency tree... Done Reading state information... Done software-properties-common is already the newest version (0.99.22.9). wget is already the newest version (1.21.2-2ubuntu1.1). 0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded. accardo_cloud@cloudshell:~$ wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb --2024-07-22 20:53:23-- https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb Resolving github.com (github.com)... 140.82.121.4 Connecting to github.com (github.com)|140.82.121.4|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/131323182/b6d71780-ab7e-11ea-9b13-e2875e48ec6c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240722%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240722T205323Z&X-Amz-Expires=300&X-Amz-Signature=5de5fdb282ced1e10cf6d5c7df3aefeed7b19b514f617a0f472030ba9a5c3cb1&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=131323182&response-content-disposition=attachment%3B%20filename%3Dwkhtmltox_0.12.6-1.bionic_amd64.deb&response-content-type=application%2Foctet-stream [following] --2024-07-22 20:53:23-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/131323182/b6d71780-ab7e-11ea-9b13-e2875e48ec6c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240722%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240722T205323Z&X-Amz-Expires=300&X-Amz-Signature=5de5fdb282ced1e10cf6d5c7df3aefeed7b19b514f617a0f472030ba9a5c3cb1&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=131323182&response-content-disposition=attachment%3B%20filename%3Dwkhtmltox_0.12.6-1.bionic_amd64.deb&response-content-type=application%2Foctet-stream Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ... Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 15729530 (15M) [application/octet-stream] Saving to: ‘wkhtmltox_0.12.6-1.bionic_amd64.deb’
wkhtmltox_0.12.6-1.bionic_amd64.deb 100%[========================================================================================>] 15.00M --.-KB/s in 0.06s
2024-07-22 20:53:23 (232 MB/s) - ‘wkhtmltox_0.12.6-1.bionic_amd64.deb’ saved [15729530/15729530]
accardo_cloud@cloudshell:~$ sudo apt-get install -f ./wkhtmltox_0.12.6-1.bionic_amd64.deb
You are running apt-get inside of Cloud Shell. Note that your Cloud Shell
machine is ephemeral and no system-wide change will persist beyond session end.
To suppress this warning, create an empty ~/.cloudshell/no-apt-get-warning file. The command will automatically proceed in 5 seconds or on any key.
Visit https://cloud.google.com/shell/help for more information.
Reading package lists... Done Building dependency tree... Done Reading state information... Done Note, selecting 'wkhtmltox' instead of './wkhtmltox_0.12.6-1.bionic_amd64.deb' Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
The following packages have unmet dependencies: wkhtmltox : Depends: libssl1.1 but it is not installable E: Unable to correct problems, you have held broken packages. accardo_cloud@cloudshell:~ sudo apt-get install -f ./wkhtmltox_0.12.6-1.bionic_amd64.deb
You are running apt-get inside of Cloud Shell. Note that your Cloud Shell
machine is ephemeral and no system-wide change will persist beyond session end.
To suppress this warning, create an empty ~/.cloudshell/no-apt-get-warning file. The command will automatically proceed in 5 seconds or on any key.
Visit https://cloud.google.com/shell/help for more information.
Reading package lists... Done Building dependency tree... Done Reading state information... Done Note, selecting 'wkhtmltox' instead of './wkhtmltox_0.12.6-1.bionic_amd64.deb' Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
The following packages have unmet dependencies: wkhtmltox : Depends: libssl1.1 but it is not installable E: Unable to correct problems, you have held broken packages. accardo_cloud@cloudshell:~ apt-get
You are running apt-get inside of Cloud Shell. Note that your Cloud Shell
machine is ephemeral and no system-wide change will persist beyond session end.
To suppress this warning, create an empty ~/.cloudshell/no-apt-get-warning file. The command will automatically proceed in 5 seconds or on any key.
Visit https://cloud.google.com/shell/help for more information.
apt 2.4.12 (amd64) Usage: apt-get [options] command apt-get [options] install|remove pkg1 [pkg2 ...] apt-get [options] source pkg1 [pkg2 ...]
apt-get is a command line interface for retrieval of packages and information about them from authenticated sources and for installation, upgrade and removal of packages together with their dependencies.
Most used commands: update - Retrieve new lists of packages upgrade - Perform an upgrade install - Install new packages (pkg is libc6 not libc6.deb) reinstall - Reinstall packages (pkg is libc6 not libc6.deb) remove - Remove packages purge - Remove packages and config files autoremove - Remove automatically all unused packages dist-upgrade - Distribution upgrade, see apt-get(8) dselect-upgrade - Follow dselect selections build-dep - Configure build-dependencies for source packages satisfy - Satisfy dependency strings clean - Erase downloaded archive files autoclean - Erase old downloaded archive files check - Verify that there are no broken dependencies source - Download source archives download - Download the binary package into the current directory changelog - Download and display the changelog for the given package
See apt-get(8) for more information about the available commands. Configuration options and syntax is detailed in apt.conf(5). Information about how to configure sources can be found in sources.list(5). Package and version choices can be expressed via apt_preferences(5). Security details are available in apt-secure(8). This APT has Super Cow Powers. accardo_cloud@cloudshell:~$
Sembra che tu stia tentando di installare wkhtmltopdf all'interno di Google Cloud Shell, ma stai riscontrando problemi legati alla dipendenza libssl1.1, che non è disponibile nei repository per la tua distribuzione. Inoltre, è importante notare che Google Cloud Shell fornisce un ambiente temporaneo, quindi le modifiche non persisteranno al termine della sessione.
Un modo per superare questi problemi di dipendenza in un ambiente temporaneo come Google Cloud Shell è utilizzare un container Docker preconfigurato che include wkhtmltopdf.
Ecco come puoi farlo:
Assicurati che Docker sia installato: Il Cloud Shell di Google Cloud dovrebbe già avere Docker installato. Puoi verificare eseguendo:
docker --version
Esegui un container Docker con wkhtmltopdf:
Puoi utilizzare un'immagine Docker che ha già wkhtmltopdf installato. Ad esempio:
docker run -it --rm acleancoder/wkhtmltopdf-alpine sh
Questo comando esegue un container Docker utilizzando l'immagine acleancoder/wkhtmltopdf-alpine. Una volta che il container è avviato, sarai all'interno di una shell del container.
Usa wkhtmltopdf all'interno del container:
Una volta dentro il container, puoi usare wkhtmltopdf direttamente. Ad esempio:
wkhtmltopdf http://www.google.com google.pdf
Questo convertirà la pagina web di Google in un file PDF chiamato google.pdf all'interno del container. Se desideri copiare il file all'esterno del container, dovrai montare una directory dal tuo host al container usando l'opzione -v di Docker.
Montare directory dal host al container (opzionale): Se desideri salvare i file nel tuo Cloud Shell, puoi montare una directory dal tuo ambiente Cloud Shell al container. Ad esempio:
docker run -it --rm -v /path/to/host/dir:/path/in/container acleancoder/wkhtmltopdf-alpine sh
Qui, sostituisci /path/to/host/dir con il percorso della directory nel tuo ambiente Cloud Shell e /path/in/container con il percorso all'interno del container.
Convertire un file HTML già presente in Cloud Shell: Puoi anche convertire direttamente un file HTML presente nell'ambiente Cloud Shell:
docker run -it --rm -v ${PWD}:/workspace -w /workspace acleancoder/wkhtmltopdf-alpine wkhtmltopdf input.html output.pdf
Questo comando monta la directory corrente ${PWD} nell'ambiente Cloud Shell alla directory /workspace nel container, quindi esegue wkhtmltopdf all'interno del container sulla directory montata.
Utilizzando questa strategia con Docker, puoi evitare problemi di dipendenza e garantire che wkhtmltopdf sia disponibile per la durata della tua sessione di Cloud Shell.
Not yet included in a published release.