stopping at a working point for now. pdf only but crops correctly at least

This commit is contained in:
Josh North 2014-08-28 21:40:30 -04:00
parent 57b8120e98
commit b678c03f55

View File

@ -24,21 +24,21 @@
<div class="pure-control-group">
<legend><h3>Device Setup</h3></legend>
<label for="device">Device</label>
<select name="device" id="device" class="pure-input-rounded">
<select name="device" id="device" class="pure-input-1-2">
<option value="epkowa:net:pr01.lzu01.point808.com" selected="selected">pr01 (Epson WF-2540)</option>
<option value="hpaio:/net/Deskjet_F4500_series?ip=192.168.101.222">pr02 (HP DeskJet F4580)</option>
</select>
</div>
<div class="pure-control-group">
<label for="source">Feed Source</label>
<select name="source" id="source" class="pure-input-rounded">
<option value="Automatic Document Feeder" selected="selected">Automatic Document Feeder</option>
<label for="source">Source</label>
<select name="source" id="source" class="pure-input-1-2">
<option value="Automatic Document Feeder" selected="selected">Document Feeder</option>
<option value="Flatbed">Flatbed</option>
</select>
</div>
<div class="pure-control-group">
<label for="mode">Colors</label>
<select name="mode" id="mode" class="pure-input-rounded">
<select name="mode" id="mode" class="pure-input-1-2">
<option value="Binary">Black & White</option>
<option value="Gray" selected="selected">Grayscale</option>
<option value="Color">Color</option>
@ -46,12 +46,14 @@
</div>
<div class="pure-control-group">
<label for="sResolution">Resolution</label>
<select name="sResolution" id="sResolution" class="pure-input-rounded">
<select name="sResolution" id="sResolution" class="pure-input-1-2">
<option value="75" selected="selected">75dpi (FASTEST!)</option>
<option value="300">300dpi</option>
<option value="600">600dpi (SLOW!)</option>
</select>
</div>
</fieldset>
<fieldset>
<input type="hidden" name="scan" value="yes" />
<input type="submit" onclick="this.disabled=true;this.value='Scanning - PLEASE be patient!';this.form.submit();" value="Scan!" class="pure-button pure-button-primary" />
</div>
@ -59,33 +61,33 @@
<div class="pure-control-group">
<legend><h3>File Options</h3></legend>
<label for="filetype">File Type</label>
<select name="filetype" id="filetype" class="pure-input-rounded">
<select name="filetype" id="filetype" class="pure-input-1-2">
<option value="pdf" selected="selected">PDF (multipage)</option>
<option value="jpg">JPG (image)</option>
</select>
</div>
<div class="pure-control-group">
<label for="filenaming">File Naming</label>
<input name="filenaming" type="text" id="filenaming" class="pure-input-rounded" placeholder="Append to filename">
<input name="filenaming" type="text" id="filenaming" class="pure-input-1-2" placeholder="Append to filename">
</div>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<div class="pure-control-group">
<legend><h3>Page Size (in mm)</h3></legend>
<label for="l">X-Start (top-left)</label>
<input name="l" type="number" id="l" class="pure-input-rounded" value="0">
<input name="l" type="number" id="l" class="pure-input-1-2" value="0">
</div>
<div class="pure-control-group">
<label for="t">Y-Start (top-left)</label>
<input name="t" type="number" id="t" class="pure-input-rounded" value="0">
<input name="t" type="number" id="t" class="pure-input-1-2" value="0">
</div>
<div class="pure-control-group">
<label for="sX">Width (215.9=8.5in)</label>
<input name="sX" type="number" id="sX" class="pure-input-rounded" value="215.9">
<input name="sX" type="number" id="sX" class="pure-input-1-2" value="215.9">
</div>
<div class="pure-control-group">
<label for="y">Height (279=11in)</label>
<input name="y" type="number" id="y" class="pure-input-rounded" value="279">
<input name="y" type="number" id="y" class="pure-input-1-2" value="279">
</div>
</fieldset>
</div>
@ -95,17 +97,19 @@
// initialize scanned files directory path
$scans_dir = $app_dir . $scan_dir;
// set post variables
if(isset($_POST['sResolution'])) { $pResolution = $_POST['sResolution']; };
if(isset($_POST['sX'])) { $pX = $_POST['sX']; };
if(isset($_POST['sResolution'])){$pResolution = $_POST['sResolution'];};
if(isset($_POST['sX'])){$pX = $_POST['sX'];};
// decide to use scanimage if Flatbed or scanadf if ADF
if (isset($_POST['source'])) {
if ($_POST['source']=="Flatbed") {
$scanprog = $scanimage;
// $scanprog = $scanimage;
$scanprog = $scanadf; //TEMP SET ALL TO ADF
} else {
$scanprog = $scanadf;
}
} else {
$scanprog = $scanimage;
// $scanprog = $scanimage;
$scanprog = $scanadf; //TEMP SET ALL TO ADF
}
// are we being called as a result of a scan or just initial page view?
if (isset($_POST['scan'])) {
@ -127,7 +131,7 @@
$filename = date($date_format);
}
// do it!
$process = proc_open($scanprog . " -d " . $_POST['device'] . " --output-file " . $scans_dir . $filename . "-%04d --source " . $_POST['source'] . " --mode " . $_POST['mode'] . " --resolution " . $sResolution . " -l " . $_POST['l'] . " -t " . $_POST['t'] . " -x " . $sX . " -y " . $_POST['y'], $descriptorspec, $pipes, $cwd, $env);
$process = proc_open($scanprog . " -d " . $_POST['device'] . " --output-file " . $scans_dir . $filename . "-%04d --source " . $_POST['source'] . " --mode " . $_POST['mode'] . " --resolution " . $pResolution . " -l " . $_POST['l'] . " -t " . $_POST['t'] . " -x " . $pX . " -y " . $_POST['y'], $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
$errors = stream_get_contents($pipes[2]);
$output = stream_get_contents($pipes[1]);
@ -149,7 +153,7 @@
//exec($convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg");
// make a (multi-page) pdf file from the scanned pnm files
// we have to set density to match the scan resolution and then calculate the width to pixels in order to make the pdf correct
exec($convert . ' -density ' . $sResolution . ' -page ' . $sX . ' ' . $path . ' ' . $scans_dir . $filename . '.pdf');
exec($convert . ' -density ' . $pResolution . ' ' . $path . ' ' . $scans_dir . $filename . '.pdf');
// $output = $convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg";
// $output .= ($convert . " " . $path . " " . $scans_dir . $filename . ".pdf");
echo "Scan Successful!";
@ -180,5 +184,62 @@
?>
</div>
</div>
<!-- include jQuery library -->
<script src="//code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function () {
/*
* check browser supports local storage
*/
if (localStorage) {
/*
* if form field values exist in local storage use
* them to populate the form when the page loads
*/
if (localStorage.type) {
$("#type").find("option[value=" + localStorage.type + "]").attr("selected", true);
}
if (localStorage.name) {
$("#name").val(localStorage.name);
}
if (localStorage.email) {
$("#email").val(localStorage.email);
}
if (localStorage.message) {
$("#message").val(localStorage.message);
}
if (localStorage.subscribe === "checked") {
$("#subscribe").attr("checked", "checked");
}
/*
* when a form field changes store it's value in local storage
*/
$("input[type=text],select,textarea").change(function(){
$this = $(this);
localStorage[$this.attr("name")] = $this.val();
});
$("input[type=checkbox]").change(function(){
$this = $(this);
localStorage[$this.attr("name")] = $this.attr("checked");
});
$("form")
/*
* clear local storage when the form is submitted
*/
.submit(function(){
localStorage.clear();
})
/*
* output local storage to the console each time the form changes
* (you may want to remove this code on the production server)
*/
.change(function(){
console.log(localStorage);
});
}
});
</script>
</body>
</html>