[impression] ajout d'un script qui passe par l'interface web pour imprimer des pdf
Ignore-this: 236b0a5a9ea75e188b145649d6ac3a8e (premier fichier caml dans /usr/scripts) darcs-hash:20090524225145-bd074-79f87bc8b7510de203fba7bd3d57d0d5bc639a61.gz
This commit is contained in:
parent
8fe05f79d9
commit
ac3187e40b
1 changed files with 158 additions and 0 deletions
158
impression/wrapper_canon.ml
Normal file
158
impression/wrapper_canon.ml
Normal file
|
@ -0,0 +1,158 @@
|
|||
(*
|
||||
* WRAPPER_CANON.ML--
|
||||
*
|
||||
* Copyright (C) 2009 Antoine Durand-Gasselin
|
||||
* Author: Antoine Durand-Gasselin <adg@crans.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*)
|
||||
|
||||
(* #use "topfind";;
|
||||
#require "perl";;
|
||||
#require "unix";; *)
|
||||
|
||||
let (%) a b = Printf.sprintf a b;;
|
||||
let (&) f x = f x
|
||||
|
||||
open Perl
|
||||
open Unix
|
||||
open Pl_WWW_Mechanize
|
||||
|
||||
let timestamp = (** on a besoin d'un timestamp *)
|
||||
"%d" % (int_of_float (Unix.time()))
|
||||
|
||||
(** {1 : Fonctions de conversion des options} *)
|
||||
let filename = (** le nom du fichier pdf *) ref ""
|
||||
|
||||
let copies = ref 1
|
||||
let _Copies () = "%d" % !copies
|
||||
|
||||
let papier = ref "a4"
|
||||
let _MediaSize () = match !papier with
|
||||
"a4" | "A4" -> "5"
|
||||
| "a3" | "A3" -> "6"
|
||||
| "A5" -> "16" | "B4" -> "12" | "B5" -> "13" | "LTR" -> "1" | "LGL" -> "2"
|
||||
| "11x17" -> "3" | "EXEC" -> "4" | "Com-10" -> "7" | "Monarch" -> "8"
|
||||
| "C5 Env" -> "9" | "B5 Env" -> "10" | "DL Env" -> "11"
|
||||
| _ -> raise (Arg.Bad ("%s wrong papersize" % !papier))
|
||||
|
||||
let papertype = ref "Ordinaire"
|
||||
let _MediaType () = List.assoc !papertype& List.map (fun (x,y) -> y,x)
|
||||
[ "0", "Ordinaire"; "2", "Recyclé"; "3", "Couleur"; "21", "Ordinaire (Epais)";
|
||||
"22", "Ordinaire (Fin)"; "1", "Papier épais 1"; "16", "Papier épais 2";
|
||||
"9", "Carte postale"; "10", "Carte postale"; "11", "Enveloppe";
|
||||
"6", "Transparent"; "23", "Transparent"; "24", "Couché"; "5", "Calque";
|
||||
"7", "Etiquettes"; "12", "Papier machine"; "14", "Pré-perforé" ]
|
||||
|
||||
let expand = ref false
|
||||
let _FitSize () = if !expand then "1" else "0"
|
||||
|
||||
let duplex = ref true
|
||||
let binding_long_edge = ref true
|
||||
let _DuplexType() =
|
||||
if !duplex then if !binding_long_edge then "2" else "1" else "0"
|
||||
|
||||
let agrafage = ref true
|
||||
let piqure = ref false
|
||||
let _Sort() =
|
||||
if !piqure then "3" else
|
||||
if !agrafage then "134" else "1"
|
||||
|
||||
let agrafe = ref "NW"
|
||||
let _StapleType () = List.assoc !agrafe
|
||||
[ "NW","5"; "NE","6"; "SW","7"; "SE","8"; "N","1"; "S","2"; "W","3"; "E","4"]
|
||||
|
||||
let couleur = ref false
|
||||
let _ColorMode () = if !couleur then "2" else "1"
|
||||
|
||||
|
||||
(** {1: Le formulaire} *)
|
||||
let fields =
|
||||
[ "Url","http://"; "Mode","100"; "ManualNo","0"; "DocPasswd","";
|
||||
"WebUserName",""; "WebPasswd",""; "PunchPos","0"; "Annotation","2";
|
||||
"C_Render","0"; "C_RGB_Pro","1"; "C_CMYK_Pro","4";"C_OUT_Pro","1";
|
||||
"C_GRAY_Pro","1"; "C_Matching","0"; "SPOT_Color","1"; "C_Pure_B","1";
|
||||
"C_B_OVPrn","1"; "C_Bright", "100"; "C_Gray_Com","1";"C_OVR_EFF","1";
|
||||
"WidePrn","0"; "HalfToneTxt","1"; "HalfToneGrp","1"; "HalfToneImg","1";
|
||||
"AstIntensity","2"; "AstText","0"; "AstGrap", "1"; "AstImag","1";
|
||||
"StoreBox","0"; "BoxNo","00"; "RGBDLName",""; "CMYKDLName","";
|
||||
"OUTDLName",""; "BOXName",""; "Flag","Exec_Data_Pdf"; "Direct","100";
|
||||
"BookType","2"; "NupPrint","1"; "NupStart","0"; "Resolution","1";
|
||||
"PageMode","0"; "StartPage","1"; "EndPage","1"; "ManualFeed", "0";
|
||||
"Dummy",timestamp;
|
||||
|
||||
"Copies", _Copies();
|
||||
"MediaSize", _MediaSize();
|
||||
"MediaType", _MediaType();
|
||||
"FitSize", _FitSize();
|
||||
"DuplexType", _DuplexType();
|
||||
"Sort", _Sort();
|
||||
"StapleType", _StapleType();
|
||||
"ColorMode", _ColorMode();
|
||||
"File", !filename
|
||||
]
|
||||
|
||||
let set_positive r s =
|
||||
try let a = int_of_string s in assert (a>0); r := a
|
||||
with _ -> raise (Arg.Bad "copies doivent être un entier positif")
|
||||
|
||||
let options = Arg.align
|
||||
[ "-#", Arg.String (set_positive copies), "N imprime N copies";
|
||||
"-PageSize", Arg.Set_string papier, "FORMAT Format du papier";
|
||||
"-MediaType", Arg.Set_string papertype, "TYPE Type du papier";
|
||||
"-pdf-expand", Arg.Set expand, " Agrandir/Reduire en fonction du papier";
|
||||
"-one-sided", Arg.Clear duplex, " Impression recto";
|
||||
"-two-sided", Arg.Set duplex, " Impression recto/verso";
|
||||
"-two-sided-short-edge", Arg.Clear binding_long_edge,
|
||||
" Reliure sur le bord court";
|
||||
"-Staple", Arg.Set agrafage, " Agrafage";
|
||||
"-StapleLocation", Arg.Set_string agrafe,
|
||||
"AZ Agrafe au NW,NE,SE,SW,N,S,E,W";
|
||||
"-CNSaddleStitch", Arg.Set piqure, " Mode livret";
|
||||
"-Monochrom", Arg.Clear couleur, " Impression en noir et blanc";
|
||||
"-Color", Arg.Set couleur, " Impression en couleurs";
|
||||
]
|
||||
|
||||
let usage = "Usage: wrapper_canon [OPTIONS] FILE"
|
||||
|
||||
let argv = ref 0
|
||||
let () = Arg.parse options (fun s -> incr argv; filename := s) usage
|
||||
|
||||
let () =
|
||||
if !argv <> 1 then raise (Arg.Bad "Wrong number of file")
|
||||
|
||||
(** {1 : Initialisations} *)
|
||||
let printer = (** url de l'imprimante *)
|
||||
ref "https://imprimante.adm.crans.org/"
|
||||
|
||||
let b =
|
||||
(** On initialise le "browser" *)
|
||||
let sv = Perl.call_class_method "WWW::Mechanize" "new" [] in
|
||||
let browser = new Pl_WWW_Mechanize.www_mechanize sv in
|
||||
|
||||
(* On a besoin d'un user_agent connu *)
|
||||
browser#agent_alias (List.nth browser#known_agent_aliases 1);
|
||||
|
||||
(* On récupère un cookie, parce que les cookies c'est bon *)
|
||||
browser#get !printer;
|
||||
|
||||
browser#get (!printer ^ "ppdf.cgi?Type=PDF&Dummy=%s" % timestamp);
|
||||
browser
|
||||
|
||||
|
||||
(* On balance la sauce *)
|
||||
let resp = b#submit_form ~form_name:"PDF_SEND_FORM" ~fields ();;
|
||||
|
||||
print_string resp#as_string;;
|
Loading…
Add table
Add a link
Reference in a new issue