1 | #! /usr/bin/env python |
---|
2 | # -*- coding: ISO-8859-15 -*- |
---|
3 | # |
---|
4 | # pkipplib : IPP and CUPS support for Python |
---|
5 | # |
---|
6 | # (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com> |
---|
7 | # This program is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # This program is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | # |
---|
20 | # Sample code to print a PDF document |
---|
21 | # |
---|
22 | from pkipplib import pkipplib |
---|
23 | |
---|
24 | # Use CUPS server on localhost:631 |
---|
25 | cups=pkipplib.CUPS() |
---|
26 | |
---|
27 | # Create a new request with correct operation id |
---|
28 | req=cups.newRequest(operationid=pkipplib.IPP_PRINT_JOB) |
---|
29 | |
---|
30 | # Fill the required parameters |
---|
31 | req.operation["requesting-user-name"] = ("nameWithoutLanguage", "jerome") |
---|
32 | req.operation["printer-uri"] = ("uri", cups.identifierToURI("printers", "HP2100")) |
---|
33 | req.operation["document-format"] = ("mimeMediaType", "application/pdf") |
---|
34 | |
---|
35 | # Read the PDF datas and make them part of the request |
---|
36 | inputfile = open("testpage.pdf", "rb") |
---|
37 | req.data = inputfile.read() |
---|
38 | inputfile.close() |
---|
39 | |
---|
40 | # Send all this to CUPS |
---|
41 | response = cups.doRequest(req) |
---|