root / pkipplib / trunk / tests / printjob.py @ 2700

Revision 46, 1.5 kB (checked in by jerome, 17 years ago)

Added a sample script to show how to print a PDF document.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id Revision
Line 
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#
22from pkipplib import pkipplib
23
24# Use CUPS server on localhost:631
25cups=pkipplib.CUPS()
26
27# Create a new request with correct operation id
28req=cups.newRequest(operationid=pkipplib.IPP_PRINT_JOB)
29
30# Fill the required parameters
31req.operation["requesting-user-name"] = ("nameWithoutLanguage", "jerome")
32req.operation["printer-uri"] = ("uri", cups.identifierToURI("printers", "HP2100"))
33req.operation["document-format"] = ("mimeMediaType", "application/pdf")
34
35# Read the PDF datas and make them part of the request
36inputfile = open("testpage.pdf", "rb")
37req.data = inputfile.read()
38inputfile.close()
39
40# Send all this to CUPS
41response = cups.doRequest(req)
Note: See TracBrowser for help on using the browser.