User Tools

Site Tools


public:code:hplip_scan

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

public:code:hplip_scan [2014/10/25 18:12] (current)
Line 1: Line 1:
 +mit meinem CM1312nfi MFP lässt sich zwar wunderbar übers Netz drucken mit Linux und hplip und Scannen geht z.b. mit xsane oder simple-scan auch. Aber der Scan lässt sich nur über den PC starten. Das heißt man muss zum Drucker, die Vorlage einlegen, wieder zurück zum Rechner um den Scan-Prozess zu starten und dann wieder zurück zum Drucker um die Vorlage wieder raus zu nehmen.
  
 +Unter Windows kann man die Scan-Taste am Drucker nutzen um von dort direkt den Scan zu starten. Die fertige Datei landet dann auf dem PC.
 +
 +Dieses Script bildet einen Teil der Funktion nach. Wenn man Windows benutzt kann man über den Rechner verschiedene Einstellung im Drucker hinterlegen (Auflösung,​ Dateiformat usw) und man müsste auch am Drucker den Ziel-PC auswählen können (das war zumindest im Büro bei unserem Drucker so, ob das der CM1312nfi auch so macht weiß ich nicht). Das funktioniert mit diesem Script nicht. Die Einstellung sind im Script festgelegt und nicht am Drucker und man kann nur von einem Rechner aus scannen.
 +
 +Das Script erfordert folgende Programme
 +  * hplip
 +  * imagemagick
 +  * scanimage (unter Debian im Paket sane-utils)
 +  * wget
 +  * xpath (unter Debian im Paket libxml-xpath-perl)
 +
 +Vorlagenglas und ADF werden automatisch unterschieden. Bei verwendung des ADF wird jedes Blatt in ein Dokument gescant. Alle diese Einzel-Dokumente werden zu einem zusammengefügt sobal kein Blatt mehr im ADF liegt.
 +Für andere Geräte muss die device-URL natürlich noch angepasst werden.
 +
 +Das Script steht unter modifizierter BSD-Lizenz
 +
 +<​code>​
 +Copyright (c) 2014, Matthias Eller <​matthias@eller-net.de>​
 +All rights reserved.
 +Redistribution and use in source and binary forms, with or without modification,​ are permitted provided
 +that the following conditions are met:
 +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
 +following disclaimer.
 +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
 +following disclaimer in the documentation and/or other materials provided with the distribution.
 +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
 +promote products derived from this software without specific prior written permission.
 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ​
 +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ​
 +</​code>​
 +
 +<code bash>
 +#!/bin/bash
 +
 +# Copyright (c) 2014, Matthias Eller <​matthias@eller-net.de>​
 +# All rights reserved.
 +# Redistribution and use in source and binary forms, with or without modification,​ are permitted provided that the following conditions are met:
 +# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 +# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 +# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ​
 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ​
 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ​
 +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 +
 +
 +NOTIFICATIONS_FILE=/​tmp/​notifications.xml
 +IP_ADDRESS=192.168.0.110
 +RESOLUTION=150
 +MODE=Gray
 +
 +if [ -f $NOTIFICATIONS_FILE ]; then 
 + rm $NOTIFICATIONS_FILE ​
 +fi
 +
 +while true
 +do
 + wget --quiet http://​$IP_ADDRESS/​hp/​device/​notifications.xml -O $NOTIFICATIONS_FILE
 +
 + if [ -s /​tmp/​notifications.xml ]; then
 + xpath -q -e '//​Notifications/​StartScanNotifications/​StartScan[text()=1]'​ $NOTIFICATIONS_FILE | grep '>​1<'​ > /dev/null
 + if [ $? -eq 0 ]; then
 + echo "start scan"
 +
 + xpath -q -e '//​Notifications/​StartScanNotifications/​ADFLoaded[text()=1]'​ $NOTIFICATIONS_FILE | grep '>​1<'​ > /dev/null
 + if [ $? -eq 0 ]; then
 + echo "doing ADF Scan"
 + while xpath -q -e '//​Notifications/​StartScanNotifications/​ADFLoaded[text()=1]'​ $NOTIFICATIONS_FILE | grep '>​1<'​ > /dev/null
 + do
 + echo "ADF Loaded"​
 + filename=/​tmp/​ADF_$(date +%s).pdf
 + scanimage --source ADF --mode $MODE --resolution $RESOLUTION -d hpaio:/​net/​HP_Color_LaserJet_CM1312nfi_MFP?​ip=$IP_ADDRESS | convert - $filename
 + sleep 1s
 + #​refresh notification
 + rm $NOTIFICATIONS_FILE
 + wget --quiet http://​$IP_ADDRESS/​hp/​device/​notifications.xml -O $NOTIFICATIONS_FILE
 + done
 + pdfjoin /​tmp/​ADF*.pdf --outfile /​tmp/​JOINED_$(date +%s).pdf > /dev/null
 + rm /​tmp/​ADF*.pdf
 + rm $NOTIFICATIONS_FILE
 + else
 + filename=/​tmp/​doc_$(date +%s).pdf
 + scanimage --mode $MODE --resolution $RESOLUTION -d hpaio:/​net/​HP_Color_LaserJet_CM1312nfi_MFP?​ip=$IP_ADDRESS | convert - $filename
 + rm $NOTIFICATIONS_FILE
 + fi
 + fi
 + fi
 +done
 +rm /​tmp/​notifications.xml
 +</​code>​
public/code/hplip_scan.txt · Last modified: 2014/10/25 18:12 (external edit)