提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|使用教程|编辑:龚雪|2013-11-19 09:08:44.000|阅读 224 次
概述:存储和检索数字化文档是任何文档管理工作流过程的一个重要特征。本文我们将介绍如何使用ASP.NET Web程序中的文档扫描功能将扫描文件保存为PDF文档,并保存至SQL Server数据库中。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
存储和检索数字化文档是任何文档管理工作流过程的一个重要特征。本文我们将介绍如何使用ASP.NET Web程序中的文档扫描功能将扫描文件保存为PDF文档,并保存至SQL Server数据库中。
在本文中我们将使用Dynamic Web TWAIN来加快文档扫描,上传和显示功能的开发进程。
文件扫描
由于Dynamic Web TWAIN是一个客户端SDK,我们将使用JavaScript来调用它的方法/属性。有了扫描识别工具Dynamic Web TWAIN,你可以自定义扫描设置,如分辨率,像素类型,亮度,对比度,页面大小等。本文,我们将重点介绍如何从SQL Server中储存和检索图像。为此,我们将只包括一个简单的扫描过程。
function acquireImage() { if (_divDWTSourceContainerID == "") DWObject.SelectSource(); else DWObject.SelectSourceByIndex(document.getElementById(_divDWTSourceContainerID).selectedIndex); //select a TWAIN scanner DWObject.CloseSource(); //make sure the source is closed before using it DWObject.OpenSource(); DWObject.IfShowUI = document.getElementById("ShowUI").checked; //show or hide the user interface of the TWAIN scanner var i; for (i = 0; i < 3; i++) { if (document.getElementsByName("PixelType").item(i).checked == true) DWObject.PixelType = i; } // set the pixel type of the acquired images, B/W, gray or color DWObject.Resolution = document.getElementById("Resolution").value; //set the resolution DWObject.IfFeederEnabled = document.getElementById("ADF").checked; //scan images from auto feeder DWObject.IfDuplexEnabled = document.getElementById("Duplex").checked; //enable duplex scanning appendMessage("Pixel Type: " + DWObject.PixelType + "<br />Resolution: " + DWObject.Resolution + "<br />"); DWObject.IfDisableSourceAfterAcquire = true; DWObject.AcquireImage(); //start document scanning }
将扫描图像作为个多页PDF保存至SQL Server
扫描完成后,你可以将图像保存为多种格式:BMP、PNG、JPG、TIF、PDF、多页PDF或多页TIF。在这个例子中,我们将扫描图像保存为一个多页PDF文件。代码如下所示:
function btnUpload_onclick() { if (!checkIfImagesInBuffer()) { return; } var i, strHTTPServer, strActionPage, strImageType; _txtFileName.className = ""; if (!strre.test(_txtFileName.value)) { _txtFileName.className += " invalid"; _txtFileName.focus(); appendMessage("Please input file name.<br />Currently only English names are allowed.<br />"); return; } //DWObject.MaxInternetTransferThreads = 5; strHTTPServer = _strServerName; DWObject.HTTPPort = _strPort; var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1); strActionPage = CurrentPath + _strActionPage; // the aspx page for receiving image data on the server side var redirectURLifOK = CurrentPath + "online_demo_list.aspx"; var uploadfilename = _txtFileName.value + "." + document.getElementsByName("ImageType").item(i).value; DWObject.HTTPUploadAllThroughPostAsPDF( strHTTPServer, strActionPage, uploadfilename ); //upload images as multi-page PDF file _strTempStr = _strTempStr + "Upload: "; if (checkErrorString()) { if (strActionPage.indexOf("SaveToFile") != -1) alert(DWObject.ErrorString)//if save to file. else window.location = redirectURLifOK; } }
Action Page- SaveToDB.aspx
动作页面用于接收来自扫描图像的图像数据。
<%@ Page Language="C#"%> <% try { String strImageName; int iFileLength; HttpFileCollection files = HttpContext.Current.Request.Files; HttpPostedFile uploadfile = files["RemoteFile"]; strImageName = uploadfile.FileName; iFileLength = uploadfile.ContentLength; Byte[] inputBuffer = new Byte[iFileLength]; System.IO.Stream inputStream; inputStream = uploadfile.InputStream; inputStream.Read(inputBuffer, 0, iFileLength); String strConnString; strConnString = Common.DW_ConnString; System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(strConnString); String SqlCmdText = "INSERT INTO " + Common.DW_SaveTable + " (strImageName,imgImageData) VALUES (@ImageName,@Image)"; System.Data.SqlClient.SqlCommand sqlCmdObj = new System.Data.SqlClient.SqlCommand(SqlCmdText, sqlConnection); sqlCmdObj.Parameters.Add("@Image", System.Data.SqlDbType.Binary, iFileLength).Value = inputBuffer; sqlCmdObj.Parameters.Add("@ImageName", System.Data.SqlDbType.VarChar, 255).Value = strImageName; sqlConnection.Open(); sqlCmdObj.ExecuteNonQuery(); sqlConnection.Close(); } catch { } %>
从Web页面上显示数据库中检索PDF文件
Online_demo_view.aspx用于显示PDF文档
setTimeout(function () { var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1); var strActionPage = CurrentPath + "online_demo_download.aspx"; //the ActionPage's file path strHTTPServer = location.hostname; DWObject.HTTPPort = location.port==""?80:location.port; var downloadsource = strActionPage + "?iImageIndex=<%=strImageID%>&ImageName=<%=strImageName%>&ImageExtName=<%=strImageExtName%>"; DWObject.HTTPDownloadEx(strHTTPServer, downloadsource,<%=strImageFileType %>); }, 500);
online_demo_download.aspx用于检索数据库中的图像
<%@ Page Language="C#"%> <% String strExc = ""; try { //Get the image data from the database HttpRequest request = HttpContext.Current.Request; String strImageName; String strImageExtName; String strImageID; strImageName = request["ImageName"]; strImageExtName = request["ImageExtName"]; strImageID = request["iImageIndex"]; String strConnString; strConnString = Common.DW_ConnString; System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(strConnString); System.Data.SqlClient.SqlCommand sqlCmdObj = new System.Data.SqlClient.SqlCommand("SELECT imgImageData FROM " + Common.DW_SaveTable + " WHERE iImageID= " + strImageID, sqlConnection); sqlConnection.Open(); System.Data.SqlClient.SqlDataReader sdrRecordset = sqlCmdObj.ExecuteReader(); sdrRecordset.Read(); long iByteLength; iByteLength = sdrRecordset.GetBytes(0, 0, null, 0, int.MaxValue); byte[] byFileData = new byte[iByteLength]; sdrRecordset.GetBytes(0, 0, byFileData, 0, Convert.ToInt32(iByteLength)); sdrRecordset.Close(); sqlConnection.Close(); sdrRecordset = null; sqlConnection = null; Response.Clear(); Response.Buffer = true; if (strImageExtName == "bmp") { Response.ContentType = "image/bmp"; } else if (strImageExtName == "jpg") { Response.ContentType = "image/jpg"; } else if (strImageExtName == "tif") { Response.ContentType = "image/tiff"; } else if (strImageExtName == "png") { Response.ContentType = "image/png"; } else if (strImageExtName == "pdf") { Response.ContentType = "application/pdf"; } try { String fileNameEncode; fileNameEncode = HttpUtility.UrlEncode(strImageName, System.Text.Encoding.UTF8); fileNameEncode = fileNameEncode.Replace("+", "%20"); String appendedheader = "attachment;filename=" + fileNameEncode; Response.AppendHeader("Content-Disposition", appendedheader); Response.OutputStream.Write(byFileData, 0, byFileData.Length); } catch (Exception exc) { strExc = exc.ToString(); DateTime d1 = DateTime.Now; string logfilename = d1.Year.ToString() + d1.Month.ToString() + d1.Day.ToString() + d1.Hour.ToString() + d1.Minute.ToString() + d1.Second.ToString() + "log.txt"; String strField1Path = HttpContext.Current.Request.MapPath(".") + "/" + logfilename; if (strField1Path != null) { System.IO.StreamWriter sw1 = System.IO.File.CreateText(strField1Path); sw1.Write(strExc); sw1.Close(); } Response.Flush(); Response.Close(); } } catch (Exception ex) { strExc = ex.ToString(); DateTime d1 = DateTime.Now; string logfilename = d1.Year.ToString() + d1.Month.ToString() + d1.Day.ToString() + d1.Hour.ToString() + d1.Minute.ToString() + d1.Second.ToString() + "log.txt"; String strField1Path = HttpContext.Current.Request.MapPath(".") + "/" + logfilename; if (strField1Path != null) { System.IO.StreamWriter sw1 = System.IO.File.CreateText(strField1Path); sw1.Write(strExc); sw1.Close(); } Response.Write(strExc); } %>
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn
文章转载自:慧都控件网本文探讨 SQL Server 中 NULL 和空值之间的区别,并讨论如何有效地处理它们。
Unity 是一款功能极其丰富的游戏引擎,允许开发人员将各种媒体集成到他们的项目中。但是,它缺少最令人兴奋的功能之一 - 将 Web 内容(例如 HTML、CSS 和 JavaScript)直接渲染到 3D 场景中的纹理上的能力。在本文中,我们将介绍如何使用 DotNetBrowser 在 Unity3D 中将 Web 内容渲染为纹理。
DevExpress v24.2帮助文档正式发布上线了,请按版本按需下载~
本教程将向您展示如何用MyEclipse构建一个Web项目,欢迎下载最新版IDE体验!
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@pclwef.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢