IPB

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> script convertir html en pdf
Options
turbin
posté 25 Jul 2014, 09:17
Message #1


Adepte de Macbidouille
*

Groupe : Membres
Messages : 75
Inscrit : 29 May 2002
Membre no 2 584



Bonjour,

Je voudrais utiliser automator avec un script pour faire de telle sorte que lorsqu'un document html arrive dans un dossier il soit automatiquement converti en pdf.

J'ai installé wkhtmltopdf comme indiqué dans un post sur ce forum (en 2007 !!) mais je ne vois pas comment ca fonctionne ensuite.

Lorsque je lance le terminal j'ai :
/usr/local/bin/wkhtmltopdf ; exit;
You need to specify atleast one input file, and exactly one output file
Use - for stdin or stdout

Name:
wkhtmltopdf 0.12.1 (with patched qt)

Synopsis:
wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>

Document objects:
wkhtmltopdf is able to put several objects into the output file, an object is
either a single webpage, a cover webpage or a table of content. The objects
are put into the output document in the order they are specified on the
command line, options can be specified on a per object basis or in the global
options area. Options from the Global Options section can only be placed in
the global options area

A page objects puts the content of a singe webpage into the output document.

(page)? <input url/file name> [PAGE OPTION]...
Options for the page object can be placed in the global options and the page
options areas. The applicable options can be found in the Page Options and
Headers And Footer Options sections.

A cover objects puts the content of a singe webpage into the output document,
the page does not appear in the table of content, and does not have headers
and footers.

cover <input url/file name> [PAGE OPTION]...
All options that can be specified for a page object can also be specified for
a cover.

A table of content object inserts a table of content into the output document.

toc [TOC OPTION]...
All options that can be specified for a page object can also be specified for
a toc, further more the options from the TOC Options section can also be
applied. The table of content is generated via XSLT which means that it can be
styled to look however you want it to look. To get an aide of how to do this
you can dump the default xslt document by supplying the
--dump-default-toc-xsl, and the outline it works on by supplying
--dump-outline, see the Outline Options section.

Description:
Converts one or more HTML pages into a PDF document, using wkhtmltopdf patched
qt.

Global Options:
--collate Collate when printing multiple copies
(default)
--no-collate Do not collate when printing multiple
copies
--copies <number> Number of copies to print into the pdf
file (default 1)
-H, --extended-help Display more extensive help, detailing
less common command switches
-g, --grayscale PDF will be generated in grayscale
-h, --help Display help
--license Output license information and exit
-l, --lowquality Generates lower quality pdf/ps. Useful to
shrink the result document space
-O, --orientation <orientation> Set orientation to Landscape or Portrait
(default Portrait)
-s, --page-size <Size> Set paper size to: A4, Letter, etc.
(default A4)
-q, --quiet Be less verbose
--read-args-from-stdin Read command line arguments from stdin
--title <text> The title of the generated pdf file (The
title of the first document is used if not
specified)
-V, --version Output version information and exit

Page Options:
--print-media-type Use print media-type instead of screen
--no-print-media-type Do not use print media-type instead of
screen (default)

Contact:
If you experience bugs or want to request new features please visit
<https://github.com/wkhtmltopdf/wkhtmltopdf/issues>

logout

Que veut dire : You need to specify atleast one input file, and exactly one output file ?? A quel endroit je précise le document entrant ???

Je ne comprends pas. Mais peut être existe t il une autre solution pour faire la conversion automatique html vers pdf..

Merci.
Go to the top of the page
 
+Quote Post
hellomorld
posté 25 Jul 2014, 09:34
Message #2


Macbidouilleur d'Or !
*****

Groupe : Membres
Messages : 6 150
Inscrit : 31 Oct 2003
Membre no 11 118



peut-être en affichant le doc html dans Safari puis en imprimant ce dernier en pdf (tout ça avec automator bien sûr) ?


--------------------
Go to the top of the page
 
+Quote Post
turbin
posté 25 Jul 2014, 09:38
Message #3


Adepte de Macbidouille
*

Groupe : Membres
Messages : 75
Inscrit : 29 May 2002
Membre no 2 584



tu peux me préciser ta pensée stp. Si je comprends bien il faudrait que je crée un processus ouvrant l'appli safari dès qu'un doc html arrive dans un dossier (via action de dossier) puis lancant le script wkhtmltopdf ? auquel cas quel est l'inérêt d'installer wkhtmltopdf ?

Ce message a été modifié par turbin - 25 Jul 2014, 09:39.
Go to the top of the page
 
+Quote Post
Jaypee
posté 25 Jul 2014, 11:29
Message #4


Macbidouilleur d'Or !
*****

Groupe : Membres
Messages : 2 486
Inscrit : 29 Aug 2002
Membre no 3 340



Aucun.
Les applis s'appuient sur le service d'impression d'OS X qui sait imprimer en PDF.

J-P
Go to the top of the page
 
+Quote Post
turbin
posté 25 Jul 2014, 12:33
Message #5


Adepte de Macbidouille
*

Groupe : Membres
Messages : 75
Inscrit : 29 May 2002
Membre no 2 584



mon objectif nb'est pas d'imprimer un doc html en pdf, je sais faire par le menu imprimer etc...
Je veux créer un automatisme qui converti un doc appelé par ex mondocument.html en mondocument.pdf
Go to the top of the page
 
+Quote Post
Guest_JacqR_*
posté 25 Jul 2014, 14:23
Message #6





Guests






Bonjour,

Citation (turbin @ 25 Jul 2014, 07:33) *
mon objectif nb'est pas d'imprimer un doc html en pdf, je sais faire par le menu imprimer etc...
Je veux créer un automatisme qui converti un doc appelé par ex mondocument.html en mondocument.pdf

Sans option spécifique , la ligne de commande sera comme ceci (exemple avec un fichier sur ton bureau) :
Code
/usr/local/bin/wkhtmltopdf "~/Desktop/monDocument.html" "~/Desktop/monDocument.pdf"


Donc pour que cela fonctionne avec ton action de dossier Automator :
Ajoute l'action "Exécuter un script Shell".
Sélectionne Shell : "/bin/bash" et Données en entrée : "comme arguments" dans le menu des popup de l'action "Exécuter un script Shell"
Supprime tout le texte dans l'action "Exécuter un script Shell", copie/colle ce texte :
Code
for f in "$@"
do
    if [[ "${f##*.}" = "html" ]]; then
       tPDF=${f%.*}.pdf
       /usr/local/bin/wkhtmltopdf "$f" "$tPDF" && echo "$tPDF"
    fi
done

Ce script vérifie que le nom du fichier se termine par ".html", si oui, il créera un PDF avec le même nom, seul l'extension sera différent.

La sortie de l'action sera la liste des chemins des fichiers PDF créé, donc si tu as d'autre chose à faire avec ces PDF, tu peux ajouter d'autres actions comme les déplacer dans un autre dossier par exemple.
Go to the top of the page
 
+Quote Post
Jaypee
posté 25 Jul 2014, 15:40
Message #7


Macbidouilleur d'Or !
*****

Groupe : Membres
Messages : 2 486
Inscrit : 29 Aug 2002
Membre no 3 340



Hellomorld et moi-même avons fait une réponse elliptique.

Ce qu'on a dit:
- Pas besoin d'outil supplémentaire pour produire du PDF, c'est déjà inclus dans l'OS.
- Utiliser Automator, l'outil qui sert à enregistrer une séquence d'opérations manuelles pour pouvoir ensuite les répéter automatiquement.
- On peut même attacher cette automation comme script de dossier pour qu'un simple glisser-déposer de plusieurs fichiers HTML dans ce dossier spécial déclenche la traduction.

Désolé pour le malentendu,
J-P

Go to the top of the page
 
+Quote Post
turbin
posté 27 Jul 2014, 16:38
Message #8


Adepte de Macbidouille
*

Groupe : Membres
Messages : 75
Inscrit : 29 May 2002
Membre no 2 584



Merci JacqR, ton script est parfaitement opérationnel. C'est exactement ce qu'il me fallait. Je suis admiratif devant cette science de la programmation et des citoyens comme toi qui ont cette capacité à résoudre les questions posées. Je ne sais pas pourquoi ca marche car je ne comprend rien à ce langage mais Encore merci.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



Nous sommes le : 19th April 2024 - 07:18