在Java中操作扫描仪

在Java中操作扫描仪源码示例:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>控件测试页面</title>
<script language="javascript" type="text/javascript" src="../js/jquery-1.4.2.min.js" ></script>
<script type="text/javascript">
$(function() {
$('#btnScan').click(function() {
document.getElementById('scaner1').scan();
}),
$('#btnUpload1').click(function() {
submit_1();

}),
$('#btnUpload2').click(function() {
submit_2();
})
});

function auto_select_server_action(){
var server_action_url;
if ($('#asp').attr("checked")==true) {
server_action_url="./submit.asp";
}else if ($('#jsp').attr("checked")==true) {
server_action_url="http://localhost:8080/pages/submit.jsp";
}else if ($('#php').attr("checked")==true) {
server_action_url="./submit.php";
}else if ($('#aspnet').attr("checked")==true) {
server_action_url="./submit.aspx";
} else{
alert('请选择服务器端技术类型!');
return ;
}
document.forms[0].action=server_action_url;
}

function submit_1(){
auto_select_server_action();
var base64_data = document.getElementById('scaner1').jpegBase64Data;
document.getElementById('picData').value=base64_data;
document.getElementById('picExt').value='.jpg';
document.forms[0].submit();
}

function submit_2(){
auto_select_server_action();
var base64_data = document.getElementById('scaner1').allImageAsPDFData;
document.getElementById('picData').value=base64_data;
alert(base64_data.length);
document.getElementById('picExt').value='.pdf';
document.forms[0].submit();
}

</script>
</head>
<body>
<form action="" name="form1" id="form1" method="post" target="_blank">
<input type="hidden" id="picData" name="picData"/>
<input type="hidden" id="picExt" name="picExt"/>
<p>请选择服务器端技术:
<label>
<input name="radio" type="radio" id="asp" value="asp" checked="checked" />
asp</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
<input type="radio" name="radio" id="jsp" value="jsp" />
jsp</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
<input type="radio" name="radio" id="aspnet" value="asp.net" />
asp.net</label>
&nbsp;&nbsp;&nbsp;&nbsp;
<label>
<input type="radio" name="radio" id="php" value="php" />
php</label>
</p>
<p>注意上传pdf格式文件时尽量使用黑白扫描格式,否则数据量过大会造成某些未调优参数的服务器端技术处理失败。</p>
<p>
<input type="button" value="扫描" id="btnScan"/>
<input type="button" value="上传单页结果" id="btnUpload1"/>
<input type="button" value="上传全部结果" id="btnUpload2"/>
</p>
<object classid="clsid:15D142CD-E529-4B01-9D62-22C9A6C00E9B" id="scaner1" 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">
<param name="jpegBase64Data" value="">
<param name="bmpBase64Data" value="">
<param name="key1" value="">
<param name="key2" value="">
</object>
</form>
</body>
</html>

 

 

 

 

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*,java.io.*" errorPage="" %>
<%
String savePath=config.getServletContext().getRealPath("/")+"//";

File tmp_path=new File(savePath);
tmp_path.mkdirs();
System.out.println("照片数据保存路径:"+savePath);


String pic_base_64_data=request.getParameter("picData");

//如果下面的代码输出true则说明需要调整服务器软件工作参数,解决接受post数据的大小限制问题,例如
//tomcat的话需要在server.xml中配置maxPostSize="0"来解除上传数据的大小限制 <Connector port="8080" protocol="HTTP/1.1"
// connectionTimeout="20000"
// redirectPort="8443" maxPostSize="0"/>
//
System.out.println(null==pic_base_64_data);

System.out.println("base64 string length:"+pic_base_64_data.length());
String fileFormat=request.getParameter("picExt");
sun.misc.BASE64Decoder decode=new sun.misc.BASE64Decoder();

byte[] datas=decode.decodeBuffer(pic_base_64_data);

String filename=String.valueOf(System.currentTimeMillis())+fileFormat;
File file=new File(savePath+filename);
OutputStream fos=new FileOutputStream(file);
System.out.println("图片文件名称:"+filename);
fos.write(datas);
fos.close();

out.print("<a href='" + filename + "'>click here</a>");
out.flush();
out.close();
%>

你可能感兴趣的:(java,PHP,SQL Server,asp.net,asp)