项目中需要控制扫描仪器扫描文稿并作为OA系统的附件保存到服务器端,在网页中控制扫描仪使用的是ScanOnWeb控件,实现了客户端通过javascript控制扫描仪扫描文稿,多页文稿全部扫描以后,保存为pdf格式,然后自动提交到php程序中去。
1.引入ScanOnWeb控件
<input type="hidden" name="picData"/>
<object classid="clsid:15D142CD-E529-4B01-9D62-22C9A6C00E9B" width="100%" height="600" codebase="../cabs/ScanOnWeb.cab#version=1,0,0,10">
<param name="Visible" value="0">
<param name="AutoScroll" value="0">
<param name="AutoSize" value="0">
<param name="AxBorderStyle" value="1">
<param name="Caption" value="scaner">
<param name="Color" value="4278190095">
<param name="Font" value="宋体">
<param name="KeyPreview" value="0">
<param name="PixelsPerInch" value="96">
<param name="PrintScale" value="1">
<param name="Scaled" value="-1">
<param name="DropTarget" value="0">
<param name="HelpFile" value>
<param name="PopupMode" value="0">
<param name="ScreenSnap" value="0">
<param name="SnapBuffer" value="10">
<param name="DockSite" value="0">
<param name="DoubleBuffered" value="0">
<param name="ParentDoubleBuffered" value="0">
<param name="UseDockManager" value="0">
<param name="Enabled" value="-1">
<param name="AlignWithMargins" value="0">
<param name="ParentCustomHint" value="-1">
</object>
2.读取pdf格式多页文稿扫描结果
var base64_data = document.getElementById('scaner1').allImageAsPDFData;
document.getElementById('picData').value=base64_data;
document.forms[0].submit();
3.php中保存扫描结果pdf文件到服务器硬盘中
<?php
$file_name = "ajax";
$pic_data=$_POST["picData"];
$real_picture_data=base64_decode($pic_data);
$file=fopen($file_name.$pic_ext,"w");
fwrite($file,$real_picture_data);
fclose($file);
echo "<a href='".$file_name.".pdf'>click here</a>";
?>