onenote2013破解版怎么用orc

onenote下载|onenote 2013 官方免费版 - 软件下载 - 绿茶软件园|
&&&&&&&&&&&&onenote 2013 官方免费版
onenote 2013 官方免费版
软件大小:308KB
软件语言:简体中文
软件授权:官方版
软件类别:办公应用
软件等级:
更新时间:
官方网站:
应用平台:/Win8/Win7/WinXP
onenote 2013是微软推出的一款云笔记软件。onenote 2013可以快速记录您的想法、添加图片、随时涂鸦、记录购物清单和检查您的待办事项等。无论您在家里、办公室还是出门在外,您的笔记都将与您如影随形。 它们会自动在云中保存和同步,因此您在所有设备上都能获得最新的笔记内容。并且,你可以与朋友/同事共享笔记,譬如和朋友一同规划假期旅游行程、共享工作会议记录或讲座笔记等。
OneNote 2013还提供了API,开发者们可以为其开发各类插件或服务了。得益于 API 的开放,微软自家现在也为 OneNote 提供了网页剪辑器(Web Clipper)的浏览器 Bookmarklet、发邮件添加笔记、Office Lens(让WindowsPhone直接给文档拍照优化并上传到笔记)等功能。而且,目前也能支持一些第三方服务了,譬如将 Feedly 里的文章内容保存到OneNote,或将 IFTTT 与 OneNote 连接等。相信随着时间推移,日后各种实用功能将会越来越多!
OneNote 用户界面的工具栏设计层次清晰,彩色标签页可以让整体分类看起来更直观,而且最吸引人的特色莫过于 OneNote 的「自由编辑模式」了,你不需要再遵守一行行的段落格式进行文字编辑了,用户可以在任意位置安放文本、图片或表格等,这点在一定程度上比印象笔记等其他类似软件更加自由随意,不过也可能让习惯了普通编辑模式的用户不适应。
onenote是微软在office07版本中推出的一款云笔记软件,用户想进行onenote2016下载的话可以下载完整版offce套装即可体验。onenote最新版的到来,为用户提供了最先进,最完美的体验。。
onenote 2013官方免费版
绿茶网友[四川省绵阳市] 15:07:43
本类推荐本类排行
热门软件热门标签飓风过岗,伏草唯存。君子慎独,修身律己。
篇一:WPF常用知识以及本项目设计总结:
篇二:基于OneNote难点突破和批量识别:
篇三:批量处理后的txt文件入库处理:
篇四:关于OneNote入库处理以及审核:
【小记】:大胆尝试才能突破,某个中医药大学有一批图片需要处理(ORC),然后进行数据挖掘。之前没有接触过ORC这个东西,但是还是应允了。在网上搜索一番,关于中文图片识别,最终敲定为基于微软的OneNote,其识别率相对较高。网上这个技术点的资料真心不多,后来于博客园找到一篇博文,但是那个程序还是bug百出,而且只是单处理。后来经过一番摸索逐个突破,批处理完成。然后进行界面设计,这些零碎工作完成后,便是入库处理。由于OneNote生成的xml文件封装好的,即不可视的。便将其代码处理生成txt文件,再进行Oracle入库处理。入库前需要文件内容审核,并且在WPF开发中数据绑定和分页中做了独特处理。现在经过半个月的工作,本项目做个阶段总结。一则知识总结便于二次开发,尽量保持程序流畅性,核心知识做以梳理;另外,相关WPF和OneNote常用技术共享,便于部分园友所需。本人技术有限,欢迎交流。项目还未结束,暂作阶段文章发布,随后相继发布。
篇二:基于OneNote难点突破和批量识别
【1】开篇概述:在对本章技术介绍前,还是梳理下思路。描述下本章功能和开发过程。做个系统大致了解之后,在粘贴出本节效果图配以完整代码,然后分拆之,个体技术剖析。这样既可以达到全局整体效果,也可以对局部技术或者知识点做以小结。功能看图描述:本程序开发基于C#+WPF,然后这些条件具备前需要安装office2010以上版本,包含OneNote即可
完整代码:
namespace OnenoteOCRDemo
/// &summary&
/// Main.xaml 的交互逻辑
/// &/summary&
public partial class Main : Window
#region 全局变量
private string __OutputFileName = string.E
private WebClient client = new WebClient();
private delegate void UpdateProgressBarDelegate(System.Windows.DependencyProperty dp, Object value);
#endregion
#region 系统函数
public Main()
InitializeComponent();
#endregion
#region 用户函数
#region 验证文件夹是否存在,以及是否为空 : 17:12:57
//验证文件夹是否存在,以及是否为空
//时间: 14:54:44
//作者:白宁超
private bool fn数据验证()
if ((bool)this.rbtn本地图片.IsChecked)
if (!Directory.Exists(this.txtfile.Text))
this.labMsg.Content = "目录不存在,重新选择!";
this.txtfile.Focus();
return true;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@txtfile.Text);
if (di.GetFiles().Length + di.GetDirectories().Length == 0)
this.labMsg.Content = "目录为空!";
this.txtfile.Focus();
return true;
if (!Directory.Exists(this.txt输出目录.Text))
this.labMsg.Content = "输出目录不存在,请重新选择。";
this.txt输出目录.Focus();
return true;
return false;
#endregion
遍历出文件中图片路径
//文件中选择所有文件处理
//时间: 17:17:29
//作者:白宁超
public List&string& GetImgPath(string Filepath)
DirectoryInfo d = new DirectoryInfo(Filepath);
ArrayList Flst = GetAll(d);
//存放图片完整路径
List&string& imgpath = new List&string&();
foreach (object o in Flst)
imgpath.Add(@txtfile.Text + "\\" + o.ToString());
return//返回图片路径集合
#endregion
获取图片的过程
private void fnStartDownload(string v_strImgPath, string v_strOutputDir, out string v_strTmpPath)
int n = v_strImgPath.LastIndexOf('/');
string URLAddress = v_strImgPath.Substring(0, n);
string fileName = v_strImgPath.Substring(n + 1, v_strImgPath.Length - n - 1);
this.__OutputFileName = v_strOutputDir + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + ".txt";
if (!Directory.Exists(System.Configuration.ConfigurationManager.AppSettings["tmpPath"]))
Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["tmpPath"]);
string Dir = System.Configuration.ConfigurationManager.AppSettings["tmpPath"];
v_strTmpPath = Dir + "\\" + fileN
this.client.DownloadFile(v_strImgPath, v_strTmpPath);
#endregion
#region//删除指定目录下的所有文件夹以及文件
private void DelFillOrDir(string strPath)
if (Directory.GetDirectories(strPath).Length & 0 || Directory.GetFiles(strPath).Length & 0)
//&获得文件夹数组&
string[] strDirs = System.IO.Directory.GetDirectories(strPath);&//&获得文件数组&
string[] strFiles = System.IO.Directory.GetFiles(strPath);&//&遍历所有子文件夹&
foreach (string strFile in strFiles)
//&删除文件夹&
System.IO.File.Delete(strFile);
}&//&遍历所有文件&
foreach (string strdir in strDirs)
{&//&删除文件&
System.IO.Directory.Delete(strdir, true);
}&//&成功&
#endregion
#region//删除文件
public static bool DeleteFile(string xmlPath)
FileInfo newFile = new FileInfo(xmlPath);
if (newFile.Exists == true)
newFile.Delete();
return true;
return false;
#endregion
#region//删除xml数据
public void DeleteXML(string xpath)
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var docc = XDocument.Parse(notebookXml);
var ns = docc.Root.Name.N
XDocument doc = XDocument.Load(xpath);
string author = "USER-";
XElement xe = (from db in
doc.Element(ns + "Page").Elements(ns + "Outline")
where db.Attribute("author").Value == author
select db).Single() as XE
xe.Remove();
doc.Save(xpath);
OCR写入Onenote和生成文字整个过程
//string xpath = @"C:\Users\Administrator\Desktop\OCR_Onenote\OnenoteOCR2.1\tmp.xml";
private void fnOCR(string v_strImgPath)
ORC(v_strImgPath);
public void ORC(string v_strImgPath)
FileInfo file = new FileInfo(v_strImgPath);
//获取图片的Base64编码
using (MemoryStream ms = new MemoryStream())
Bitmap bp = new Bitmap(v_strImgPath);
switch (file.Extension.ToLower())
case ".jpg":
bp.Save(ms, ImageFormat.Jpeg);
case ".jpeg":
bp.Save(ms, ImageFormat.Jpeg);
case ".gif":
bp.Save(ms, ImageFormat.Gif);
case ".bmp":
bp.Save(ms, ImageFormat.Bmp);
case ".tiff":
bp.Save(ms, ImageFormat.Tiff);
case ".png":
bp.Save(ms, ImageFormat.Png);
case ".emf":
bp.Save(ms, ImageFormat.Emf);
this.labMsg.Content = "不支持的图片格式。";
byte[] buffer = ms.GetBuffer();
string _Base64 = Convert.ToBase64String(buffer);
#endregion
//向Onenote2010中插入图片
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
/***************************************************************************************/
string sectionID;
onenoteApp.OpenHierarchy(@"C:\Users\Administrator\Documents\OneNote 笔记本\个人\newfile.one", null, out sectionID, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
string pageID = "{A975EE72-19C3-4C80-9C0E-EDA576DAB5C6}{1}{B0}";
onenoteApp.CreateNewPage(sectionID, out pageID, Microsoft.Office.Interop.OneNote.NewPageStyle.npsBlankPageNoTitle);
/********************************************************************************/
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var doc = XDocument.Parse(notebookXml);
var ns = doc.Root.Name.N
var pageNode = doc.Descendants(ns + "Page").FirstOrDefault();
var existingPageId = pageNode.Attribute("ID").V
if (pageNode != null)
//Image Type 只支持这些类型:auto|png|emf|jpg
string ImgExtension = file.Extension.ToLower().Substring(1);
switch (ImgExtension)
case "jpg":
ImgExtension = "jpg";
case "png":
ImgExtension = "png";
case "emf":
ImgExtension = "emf";
ImgExtension = "auto";
#endregion
var page = new XDocument(new XElement(ns + "Page",
new XElement(ns + "Outline",
new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "Image",
new XAttribute("format", ImgExtension), new XAttribute("originalPageNumber", "0"),
new XElement(ns + "Position",
new XAttribute("x", "0"), new XAttribute("y", "0"), new XAttribute("z", "0")),
new XElement(ns + "Size",
new XAttribute("width", bp.Width.ToString()), new XAttribute("height", bp.Height.ToString())),
new XElement(ns + "Data", _Base64)))))));
page.Root.SetAttributeValue("ID", existingPageId);
//保存图片进入Onenote页面
//注意以下几点:(待解决)
//1,onenote页面自动会生成一个页面,可能造成一直ocr错误。删除默认页面,新建空页
//2,图片存储在新建页面中,通过如下代码实现的,以追加存储方式进行。
onenoteApp.UpdatePageContent(page.ToString(), DateTime.MinValue);
//线程休眠时间,单位毫秒,若图片很大,则延长休眠时间,保证Onenote OCR完毕
System.Threading.Thread.Sleep(Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["WaitTIme"]));
string pageX
onenoteApp.GetPageContent(existingPageId, out pageXml, Microsoft.Office.Interop.OneNote.PageInfo.piBinaryData);
//获取OCR后的内容
FileStream tmpXml = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(tmpXml);
sw.Write(pageXml);
sw.Flush();
sw.Close();
tmpXml.Close();
//加载xml中的数据
FileStream tmpOnenote = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Open, FileAccess.ReadWrite);
XmlReader reader = XmlReader.Create(tmpOnenote);
XElement rdlc = XElement.Load(reader);
// rdlc.Save(xpath);
/*****************************************************************************************************/
XmlNameTable nameTable = reader.NameT
XmlNamespaceManager mgr = new XmlNamespaceManager(nameTable);
mgr.AddNamespace("one", ns.ToString());
StringReader sr = new StringReader(pageXml);
XElement onenote = XElement.Load(sr);
////读取xml中数据,并保存到文本中。
//XDocument doc1 = XDocument.Load(xpath);
var xml = from o in onenote.XPathSelectElements("//one:Image", mgr)
select o.XPathSelectElement("//one:OCRText", mgr).V
this.txtOCRed.Text = xml.First().ToString();
/**********************************************************************/
sr.Close();
reader.Close();
tmpOnenote.Close();
//DeleteXML(xpath);
onenoteApp.DeleteHierarchy(existingPageId);
//onenoteApp.DeletePageContent(existingPageId, "{242BE490-7BF9-43D5-B719-}{46}{B0}");
//onenoteApp.DeletePageContent(existingPageId, "{242BE490-7BF9-43D5-B719-}{50}{B0}");
#endregion
#endregion
#endregion
#region 系统事件
#region 搜索文件夹中的文件: 17:12:57
//搜索文件夹中的文件
//时间: 14:54:44
//作者:白宁超
ArrayList GetAll(DirectoryInfo dir)
ArrayList FileList = new ArrayList();//定义数组存放图片文件名
FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
FileList.Add(fi.Name);//遍历图片,并添加到数组
DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
GetAll(d);
return FileL
catch (Exception e)
labMsg.Content = e.Message + "文件夹选择方式错误,重新选择!!";
return null;
#endregion
#region 选择遍历文件夹图片
//文件中选择所有文件处理
//时间: 14:54:44
//作者:白宁超
private void btn浏览_Click(object sender, RoutedEventArgs e)
txtmulu.Text = null;
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择待处理目录";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
string foldPath = dialog.SelectedP
txtfile.Text = foldP
DirectoryInfo d = new DirectoryInfo(@txtfile.Text);
ArrayList Flst = GetAll(d);
foreach (object o in Flst)
txtmulu.Text += "正在ORC图片: 【" + o.ToString() + "】\r\n";
labMsg.Content = "打开失败!!";
#region 上传单个图片
/*OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择一个本地图片";
ofd.Multiselect =
ofd.Filter = "支持的图片格式(*.jpg,*.jpeg,*.gif,*.bmp,*.png,*.tiff,*.emf)|*.*.*.*.*.*.*.emf";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
this.txt本地图片.Text = ofd.FileN
this.img图片.Source = new BitmapImage(new Uri(ofd.FileName, UriKind.RelativeOrAbsolute));
this.labMsg.Content = "本地图片已成功加载。";
#endregion
#endregion
选择本地图片OCR转化
private void rbtn本地图片_Checked(object sender, RoutedEventArgs e)
if (this.IsInitialized)
if ((bool)this.rbtn本地图片.IsChecked)
this.txtfile.Text = string.E
this.txtfile.IsEnabled = true;
this.btn浏览.IsEnabled = true;
this.txtfile.Focus();
this.txtmulu.Text = null;
#endregion
选择需要输入处理的文件
private void btn浏览_Click_1(object sender, RoutedEventArgs e)
txtmulu.Text = null;
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择待处理目录";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
string foldPath = dialog.SelectedP
txtfile.Text = foldP
DirectoryInfo d = new DirectoryInfo(@txtfile.Text);
ArrayList Flst = GetAll(d);
foreach (object o in Flst)
txtmulu.Text += "正在ORC图片: 【" + o.ToString() + "】\r\n";
labMsg.Content = "打开失败!!";
#region 上传单个图片
/*OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择一个本地图片";
ofd.Multiselect =
ofd.Filter = "支持的图片格式(*.jpg,*.jpeg,*.gif,*.bmp,*.png,*.tiff,*.emf)|*.*.*.*.*.*.*.emf";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
this.txt本地图片.Text = ofd.FileN
this.img图片.Source = new BitmapImage(new Uri(ofd.FileName, UriKind.RelativeOrAbsolute));
this.labMsg.Content = "本地图片已成功加载。";
#endregion
#endregion
#region 选择输出文件夹
private void btn输出浏览_Click(object sender, RoutedEventArgs e)
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "请选择一个输出目录";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
this.txt输出目录.Text = fbd.SelectedP
DelFillOrDir(this.txt输出目录.Text);
#endregion
清空输出文件
private void btn清空_Click(object sender, RoutedEventArgs e)
OCRtxt.Text = "";
this.OCRtxt.Focus();
#endregion
ORC转化过程
private void btnOCR_Click(object sender, RoutedEventArgs e)
if (this.fn数据验证())
OCRtxt.Text = "";
DirectoryInfo dir = new DirectoryInfo(this.txt输出目录.Text);
if ((bool)this.rbtn本地图片.IsChecked)
List&string& imgpath = GetImgPath(@txtfile.Text);//获取图片列表
//定义进度条默认值
pb_import.Minimum = 0;
pb_import.Maximum = imgpath.Count();
double i = 0;
txtOCRed.Text = "";
OCRtxt.Text += "******************************************************************************";
foreach (object img in imgpath)
this.fnOCR(img.ToString());//遍历处理图片orc
FileInfo file = new FileInfo(img.ToString());
string name = file.Name.Substring(0, file.Name.LastIndexOf("."));
this.__OutputFileName = dir.FullName + @"\" + name + ".txt";
FileStream fs = new FileStream(this.__OutputFileName, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write(this.txtOCRed.Text);//将this.txtOCRed.Text内容写进txt文件中
sw.Flush();
sw.Close();
fs.Close();
OCRtxt.Text += "成功ORC出:
【" + name + ".txt】" + "\r\n";
//回调UI进度显示
pb_import.Value =
UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(pb_import.SetValue);
Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(i + 1) });
Thread.Sleep(1000);
if (pb_import.Value == pb_import.Maximum)
System.Windows.Forms.MessageBox.Show("数据转换完成。");
System.Windows.Forms.MessageBox.Show("数据转换失败。");
catch (Exception ex)
System.Windows.Forms.MessageBox.Show("数据转换失败:" + ex.Message + ex.StackTrace);
this.labMsg.Content = "OCR失败。";
//System.Threading.Thread.CurrentThread.Abort();
Thread.Sleep(3000);
#endregion
#region//窗体关闭
private void Window_Closing(object sender, ponentModel.CancelEventArgs e)
DirectoryInfo dir = new DirectoryInfo(System.Configuration.ConfigurationManager.AppSettings["tmpPath"]);
foreach (FileInfo file in dir.GetFiles())
file.Delete();
#endregion
#endregion
功能以及操作描述:
运行本页面如上图,然后通过选择待处理目录(含中文文字图片),和输出目录,点击ORC即可。
在待处理目录下,点击浏览按钮,然后选择相应的文件夹,后台通过判断文件夹是否存在,如果存在进行遍历,读取出所有图片,然后在本页左端文本框对图片进行显示。
然后选择输出目录中的浏览按钮,选择处理后的结果存放文件夹,此项必填。否则不执行。在每次操作浏览按钮时,会对选择的文件夹进行清空处理,这样下次操作保持干净数据。
完成以上步骤,可以进行ORC操作,操作过程中通过遍历文件夹中图片文件,在一个方面中打开OneNote接口,对图片进行处理。图片处理生成的是一个xml文件,此文件不可视,一个缓存的xml文件,随着程序结束而终止,在处理过程中通过代码解析缓存xml,将文本数据提取到一个txt文件中。同时没执行一张图片,如图左边打印成功执行的文件,同时进度条滚动,结束后进行提示。
最后打开对应文件夹里面显示生产数据与对应图片保持一致。规范字体识别率还是可以的
所遇问题以及瓶颈突破:
在描述难点之前,我还是先提取出核心ORC代码,下面再做以概述。遍历处理图片
foreach (object img in imgpath)
this.fnOCR(img.ToString());//遍历处理图片orc
FileInfo file = new FileInfo(img.ToString());
string name = file.Name.Substring(0, file.Name.LastIndexOf("."));
this.__OutputFileName = dir.FullName + @"\" + name + ".txt";
FileStream fs = new FileStream(this.__OutputFileName, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write(this.txtOCRed.Text);//将this.txtOCRed.Text内容写进txt文件中
sw.Flush();
sw.Close();
fs.Close();
OCRtxt.Text += "成功ORC出:
【" + name + ".txt】" + "\r\n";
//回调UI进度显示
pb_import.Value =
UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(pb_import.SetValue);
Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { System.Windows.Controls.ProgressBar.ValueProperty, Convert.ToDouble(i + 1) });
Thread.Sleep(1000);
#endregion
fnOCR图片处理核心代码:下面截取核心代码,详细见付码
public void ORC(string v_strImgPath)
FileInfo file = new FileInfo(v_strImgPath);
//向Onenote2010中插入图片
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
/***************************************************************************************/
string sectionID;
onenoteApp.OpenHierarchy(@"C:\Users\Administrator\Documents\OneNote 笔记本\个人\newfile.one", null, out sectionID, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
string pageID = "{A975EE72-19C3-4C80-9C0E-EDA576DAB5C6}{1}{B0}";
onenoteApp.CreateNewPage(sectionID, out pageID, Microsoft.Office.Interop.OneNote.NewPageStyle.npsBlankPageNoTitle);
/********************************************************************************/
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var doc = XDocument.Parse(notebookXml);
var ns = doc.Root.Name.N
var pageNode = doc.Descendants(ns + "Page").FirstOrDefault();
var existingPageId = pageNode.Attribute("ID").V
var page = new XDocument(new XElement(ns + "Page",
new XElement(ns + "Outline",
new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "Image",
new XAttribute("format", ImgExtension), new XAttribute("originalPageNumber", "0"),
new XElement(ns + "Position",
new XAttribute("x", "0"), new XAttribute("y", "0"), new XAttribute("z", "0")),
new XElement(ns + "Size",
new XAttribute("width", bp.Width.ToString()), new XAttribute("height", bp.Height.ToString())),
new XElement(ns + "Data", _Base64)))))));
page.Root.SetAttributeValue("ID", existingPageId);
//保存图片进入Onenote页面
//注意以下几点:(待解决)
//1,onenote页面自动会生成一个页面,可能造成一直ocr错误。删除默认页面,新建空页
//2,图片存储在新建页面中,通过如下代码实现的,以追加存储方式进行。
onenoteApp.UpdatePageContent(page.ToString(), DateTime.MinValue);
//线程休眠时间,单位毫秒,若图片很大,则延长休眠时间,保证Onenote OCR完毕
System.Threading.Thread.Sleep(Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["WaitTIme"]));
string pageX
onenoteApp.GetPageContent(existingPageId, out pageXml, Microsoft.Office.Interop.OneNote.PageInfo.piBinaryData);
//获取OCR后的内容
FileStream tmpXml = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(tmpXml);
sw.Write(pageXml);
sw.Flush();
sw.Close();
tmpXml.Close();
//加载xml中的数据
FileStream tmpOnenote = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Open, FileAccess.ReadWrite);
XmlReader reader = XmlReader.Create(tmpOnenote);
XElement rdlc = XElement.Load(reader);
/*****************************************************************************************************/
XmlNameTable nameTable = reader.NameT
XmlNamespaceManager mgr = new XmlNamespaceManager(nameTable);
mgr.AddNamespace("one", ns.ToString());
StringReader sr = new StringReader(pageXml);
XElement onenote = XElement.Load(sr);
////读取xml中数据,并保存到文本中。
//XDocument doc1 = XDocument.Load(xpath);
var xml = from o in onenote.XPathSelectElements("//one:Image", mgr)
select o.XPathSelectElement("//one:OCRText", mgr).V
this.txtOCRed.Text = xml.First().ToString();
/**********************************************************************/
sr.Close();
reader.Close();
tmpOnenote.Close();
onenoteApp.DeleteHierarchy(existingPageId);
问题继续描述,未加入如上代码时,暂且不说批处理,即便是单处理。结果是无论加载多少张图片,可以生成对应txt文件,但是对应的所有txt文件里面文本内容始终一样。解决方案分析下:
是文本生成问题,于是想到每次图片生成清理出前一个xml,但是无论如何找不到xml存在,后来断点调试发现,执行onenoteApp.UpdatePageContent(page.ToString(), DateTime.MinValue);之后,打开Onenote页面会发现图片出来,说明onenote已经在处理,此刻xml已经生成。接下来&onenoteApp.GetPageContent(existingPageId, out pageXml, Microsoft.Office.Interop.OneNote.PageInfo.piBinaryData);方法把不可见的xml以字符串形式pageXml显示处理,后面就是对其处理了。证明从xml着手是不能解决问题的。
接下来就是想另一个方案:采用接口提供的DeletePageContent方法,但是面临问题在于其需要两个参数(页面序列id,和图片id),对于页面序列id通过断点可以找到,但是图片是随机的,id无法控制。因此此方案失败。
& & & 3. 在读取xml中发现this.txtOCRed.Text = xml.First().ToString();那么让去每次读取最后一条数据不就ok?对,,肯定这样,抱着坚定信心解决半日不得解。断点再经调试发现,读取的xml是不可控的,即是缓存中xml以输出参数,输出的字符串的处理。最终还不得解决。为此困惑数日。
&&&& 4. 那么在生成的缓存xml重新放置到新建的xml中,然后每次读取一条结束,删除本次记录。问题肯定解决的,大喜,于是做出如下构造:
#region//删除xml数据
public void DeleteXML(string xpath)
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var docc = XDocument.Parse(notebookXml);
var ns = docc.Root.Name.N
XDocument doc = XDocument.Load(xpath);
string author = "USER-";
XElement xe = (from db in
doc.Element(ns + "Page").Elements(ns + "Outline")
where db.Attribute("author").Value == author
select db).Single() as XE
xe.Remove();
doc.Save(xpath);
OCR写入Onenote和生成文字整个过程
//string xpath = @"C:\Users\Administrator\Desktop\OCR_Onenote\OnenoteOCR2.1\tmp.xml";
private void fnOCR(string v_strImgPath)
ORC(v_strImgPath);
public void ORC(string v_strImgPath)
FileInfo file = new FileInfo(v_strImgPath);
//获取图片的Base64编码
using (MemoryStream ms = new MemoryStream())
Bitmap bp = new Bitmap(v_strImgPath);
switch (file.Extension.ToLower())
case ".jpg":
bp.Save(ms, ImageFormat.Jpeg);
case ".jpeg":
bp.Save(ms, ImageFormat.Jpeg);
case ".gif":
bp.Save(ms, ImageFormat.Gif);
case ".bmp":
bp.Save(ms, ImageFormat.Bmp);
case ".tiff":
bp.Save(ms, ImageFormat.Tiff);
case ".png":
bp.Save(ms, ImageFormat.Png);
case ".emf":
bp.Save(ms, ImageFormat.Emf);
this.labMsg.Content = "不支持的图片格式。";
byte[] buffer = ms.GetBuffer();
string _Base64 = Convert.ToBase64String(buffer);
#endregion
//向Onenote2010中插入图片
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
/***************************************************************************************/
string sectionID;
onenoteApp.OpenHierarchy(@"C:\Users\Administrator\Documents\OneNote 笔记本\个人\newfile.one", null, out sectionID, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
string pageID = "{A975EE72-19C3-4C80-9C0E-EDA576DAB5C6}{1}{B0}";
onenoteApp.CreateNewPage(sectionID, out pageID, Microsoft.Office.Interop.OneNote.NewPageStyle.npsBlankPageNoTitle);
/********************************************************************************/
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var doc = XDocument.Parse(notebookXml);
var ns = doc.Root.Name.N
var pageNode = doc.Descendants(ns + "Page").FirstOrDefault();
var existingPageId = pageNode.Attribute("ID").V
if (pageNode != null)
//Image Type 只支持这些类型:auto|png|emf|jpg
string ImgExtension = file.Extension.ToLower().Substring(1);
switch (ImgExtension)
case "jpg":
ImgExtension = "jpg";
case "png":
ImgExtension = "png";
case "emf":
ImgExtension = "emf";
ImgExtension = "auto";
#endregion
var page = new XDocument(new XElement(ns + "Page",
new XElement(ns + "Outline",
new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "Image",
new XAttribute("format", ImgExtension), new XAttribute("originalPageNumber", "0"),
new XElement(ns + "Position",
new XAttribute("x", "0"), new XAttribute("y", "0"), new XAttribute("z", "0")),
new XElement(ns + "Size",
new XAttribute("width", bp.Width.ToString()), new XAttribute("height", bp.Height.ToString())),
new XElement(ns + "Data", _Base64)))))));
page.Root.SetAttributeValue("ID", existingPageId);
//保存图片进入Onenote页面
//注意以下几点:(待解决)
//1,onenote页面自动会生成一个页面,可能造成一直ocr错误。删除默认页面,新建空页
//2,图片存储在新建页面中,通过如下代码实现的,以追加存储方式进行。
onenoteApp.UpdatePageContent(page.ToString(), DateTime.MinValue);
//线程休眠时间,单位毫秒,若图片很大,则延长休眠时间,保证Onenote OCR完毕
System.Threading.Thread.Sleep(Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["WaitTIme"]));
string pageX
onenoteApp.GetPageContent(existingPageId, out pageXml, Microsoft.Office.Interop.OneNote.PageInfo.piBinaryData);
//获取OCR后的内容
FileStream tmpXml = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(tmpXml);
sw.Write(pageXml);
sw.Flush();
sw.Close();
tmpXml.Close();
//加载xml中的数据
FileStream tmpOnenote = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Open, FileAccess.ReadWrite);
XmlReader reader = XmlReader.Create(tmpOnenote);
XElement rdlc = XElement.Load(reader);
// rdlc.Save(xpath);
/*****************************************************************************************************/
XmlNameTable nameTable = reader.NameT
XmlNamespaceManager mgr = new XmlNamespaceManager(nameTable);
mgr.AddNamespace("one", ns.ToString());
StringReader sr = new StringReader(pageXml);
XElement onenote = XElement.Load(sr);
////读取xml中数据,并保存到文本中。
//XDocument doc1 = XDocument.Load(xpath);
var xml = from o in onenote.XPathSelectElements("//one:Image", mgr)
select o.XPathSelectElement("//one:OCRText", mgr).V
this.txtOCRed.Text = xml.First().ToString();
/**********************************************************************/
sr.Close();
reader.Close();
tmpOnenote.Close();
//DeleteXML(xpath);
onenoteApp.DeleteHierarchy(existingPageId);
//onenoteApp.DeletePageContent(existingPageId, "{242BE490-7BF9-43D5-B719-}{46}{B0}");
//onenoteApp.DeletePageContent(existingPageId, "{242BE490-7BF9-43D5-B719-}{50}{B0}");
#endregion
#endregion
& 结果还是无济于事,关键还是缓存的xml无法清理。
解决方案:搞定凌晨,无意间打开几篇英文文章(文章看不懂,只看代码),发现其原理在于图片处理过程中,催毁原始页面,新建页面即可。
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
/***************************************************************************************/
string sectionID;
onenoteApp.OpenHierarchy(@"C:\Users\Administrator\Documents\OneNote 笔记本\个人\newfile.one", null, out sectionID, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
string pageID = "{A975EE72-19C3-4C80-9C0E-EDA576DAB5C6}{1}{B0}";
onenoteApp.CreateNewPage(sectionID, out pageID, Microsoft.Office.Interop.OneNote.NewPageStyle.npsBlankPageNoTitle);
/********************************************************************************/& & & & & & &
&调用API中创建页面方法CreateNewPage,pageID通过断点可以调试到,sectionID找到本地的地址即可。然后在执行一条数据结束时,调用onenoteApp.DeleteHierarchy(existingPageId)即可。
止于此核心问题解决,下面总结下所用的文件相关操作:
1 、验证文件夹是否存在,以及是否为空&&&
#region 验证文件夹是否存在,以及是否为空 : 17:12:57
//验证文件夹是否存在,以及是否为空
//时间: 14:54:44
//作者:白宁超
private bool fn数据验证()
if ((bool)this.rbtn本地图片.IsChecked)
if (!Directory.Exists(this.txtfile.Text))
this.labMsg.Content = "目录不存在,重新选择!";
this.txtfile.Focus();
return true;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@txtfile.Text);
if (di.GetFiles().Length + di.GetDirectories().Length == 0)
this.labMsg.Content = "目录为空!";
this.txtfile.Focus();
return true;
if (!Directory.Exists(this.txt输出目录.Text))
this.labMsg.Content = "输出目录不存在,请重新选择。";
this.txt输出目录.Focus();
return true;
return false;
#endregion
2、遍历出文件中图片路径
遍历出文件中图片路径
//文件中选择所有文件处理
//时间: 17:17:29
//作者:白宁超
public List&string& GetImgPath(string Filepath)
DirectoryInfo d = new DirectoryInfo(Filepath);
ArrayList Flst = GetAll(d);
//存放图片完整路径
List&string& imgpath = new List&string&();
foreach (object o in Flst)
imgpath.Add(@txtfile.Text + "\\" + o.ToString());
return//返回图片路径集合
#endregion
3、获取图片的过程
获取图片的过程
private void fnStartDownload(string v_strImgPath, string v_strOutputDir, out string v_strTmpPath)
int n = v_strImgPath.LastIndexOf('/');
string URLAddress = v_strImgPath.Substring(0, n);
string fileName = v_strImgPath.Substring(n + 1, v_strImgPath.Length - n - 1);
this.__OutputFileName = v_strOutputDir + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + ".txt";
if (!Directory.Exists(System.Configuration.ConfigurationManager.AppSettings["tmpPath"]))
Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["tmpPath"]);
string Dir = System.Configuration.ConfigurationManager.AppSettings["tmpPath"];
v_strTmpPath = Dir + "\\" + fileN
this.client.DownloadFile(v_strImgPath, v_strTmpPath);
#endregion
4、删除指定目录下的所有文件夹以及文件
#region//删除指定目录下的所有文件夹以及文件
private void DelFillOrDir(string strPath)
if (Directory.GetDirectories(strPath).Length & 0 || Directory.GetFiles(strPath).Length & 0)
//&获得文件夹数组&
string[] strDirs = System.IO.Directory.GetDirectories(strPath);&//&获得文件数组&
string[] strFiles = System.IO.Directory.GetFiles(strPath);&//&遍历所有子文件夹&
foreach (string strFile in strFiles)
//&删除文件夹&
System.IO.File.Delete(strFile);
}&//&遍历所有文件&
foreach (string strdir in strDirs)
{&//&删除文件&
System.IO.Directory.Delete(strdir, true);
}&//&成功&
#endregion
5、删除文件
#region//删除文件
public static bool DeleteFile(string xmlPath)
FileInfo newFile = new FileInfo(xmlPath);
if (newFile.Exists == true)
newFile.Delete();
return true;
return false;
#endregion
6、删除xml数据
#region//删除xml数据
public void DeleteXML(string xpath)
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var docc = XDocument.Parse(notebookXml);
var ns = docc.Root.Name.N
XDocument doc = XDocument.Load(xpath);
string author = "USER-";
XElement xe = (from db in
doc.Element(ns + "Page").Elements(ns + "Outline")
where db.Attribute("author").Value == author
select db).Single() as XE
xe.Remove();
doc.Save(xpath);
OCR写入Onenote和生成文字整个过程
//string xpath = @"C:\Users\Administrator\Desktop\OCR_Onenote\OnenoteOCR2.1\tmp.xml";
private void fnOCR(string v_strImgPath)
ORC(v_strImgPath);
public void ORC(string v_strImgPath)
FileInfo file = new FileInfo(v_strImgPath);
//获取图片的Base64编码
using (MemoryStream ms = new MemoryStream())
Bitmap bp = new Bitmap(v_strImgPath);
switch (file.Extension.ToLower())
case ".jpg":
bp.Save(ms, ImageFormat.Jpeg);
case ".jpeg":
bp.Save(ms, ImageFormat.Jpeg);
case ".gif":
bp.Save(ms, ImageFormat.Gif);
case ".bmp":
bp.Save(ms, ImageFormat.Bmp);
case ".tiff":
bp.Save(ms, ImageFormat.Tiff);
case ".png":
bp.Save(ms, ImageFormat.Png);
case ".emf":
bp.Save(ms, ImageFormat.Emf);
this.labMsg.Content = "不支持的图片格式。";
byte[] buffer = ms.GetBuffer();
string _Base64 = Convert.ToBase64String(buffer);
#endregion
//向Onenote2010中插入图片
var onenoteApp = new Microsoft.Office.Interop.OneNote.Application();
//onenote提供的API
/***************************************************************************************/
string sectionID;
onenoteApp.OpenHierarchy(@"C:\Users\Administrator\Documents\OneNote 笔记本\个人\newfile.one", null, out sectionID, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
string pageID = "{A975EE72-19C3-4C80-9C0E-EDA576DAB5C6}{1}{B0}";
onenoteApp.CreateNewPage(sectionID, out pageID, Microsoft.Office.Interop.OneNote.NewPageStyle.npsBlankPageNoTitle);
/********************************************************************************/
string notebookX
onenoteApp.GetHierarchy(null, Microsoft.Office.Interop.OneNote.HierarchyScope.hsPages, out notebookXml);
var doc = XDocument.Parse(notebookXml);
var ns = doc.Root.Name.N
var pageNode = doc.Descendants(ns + "Page").FirstOrDefault();
var existingPageId = pageNode.Attribute("ID").V
if (pageNode != null)
//Image Type 只支持这些类型:auto|png|emf|jpg
string ImgExtension = file.Extension.ToLower().Substring(1);
switch (ImgExtension)
case "jpg":
ImgExtension = "jpg";
case "png":
ImgExtension = "png";
case "emf":
ImgExtension = "emf";
ImgExtension = "auto";
#endregion
var page = new XDocument(new XElement(ns + "Page",
new XElement(ns + "Outline",
new XElement(ns + "OEChildren",
new XElement(ns + "OE",
new XElement(ns + "Image",
new XAttribute("format", ImgExtension), new XAttribute("originalPageNumber", "0"),
new XElement(ns + "Position",
new XAttribute("x", "0"), new XAttribute("y", "0"), new XAttribute("z", "0")),
new XElement(ns + "Size",
new XAttribute("width", bp.Width.ToString()), new XAttribute("height", bp.Height.ToString())),
new XElement(ns + "Data", _Base64)))))));
page.Root.SetAttributeValue("ID", existingPageId);
//保存图片进入Onenote页面
//注意以下几点:(待解决)
//1,onenote页面自动会生成一个页面,可能造成一直ocr错误。删除默认页面,新建空页
//2,图片存储在新建页面中,通过如下代码实现的,以追加存储方式进行。
onenoteApp.UpdatePageContent(page.ToString(), DateTime.MinValue);
//线程休眠时间,单位毫秒,若图片很大,则延长休眠时间,保证Onenote OCR完毕
System.Threading.Thread.Sleep(Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["WaitTIme"]));
string pageX
onenoteApp.GetPageContent(existingPageId, out pageXml, Microsoft.Office.Interop.OneNote.PageInfo.piBinaryData);
//获取OCR后的内容
FileStream tmpXml = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(tmpXml);
sw.Write(pageXml);
sw.Flush();
sw.Close();
tmpXml.Close();
//加载xml中的数据
FileStream tmpOnenote = new FileStream(System.Configuration.ConfigurationManager.AppSettings["tmpPath"] + @"\tmp.xml", FileMode.Open, FileAccess.ReadWrite);
XmlReader reader = XmlReader.Create(tmpOnenote);
XElement rdlc = XElement.Load(reader);
// rdlc.Save(xpath);
/*****************************************************************************************************/
XmlNameTable nameTable = reader.NameT
XmlNamespaceManager mgr = new XmlNamespaceManager(nameTable);
mgr.AddNamespace("one", ns.ToString());
StringReader sr = new StringReader(pageXml);
XElement onenote = XElement.Load(sr);
////读取xml中数据,并保存到文本中。
//XDocument doc1 = XDocument.Load(xpath);
var xml = from o in onenote.XPathSelectElements("//one:Image", mgr)
select o.XPathSelectElement("//one:OCRText", mgr).V
this.txtOCRed.Text = xml.First().ToString();
/**********************************************************************/
sr.Close();
reader.Close();
tmpOnenote.Close();
//DeleteXML(xpath);
onenoteApp.DeleteHierarchy(existingPageId);
//onenoteApp.DeletePageContent(existingPageId, "{242BE490-7BF9-43D5-B719-}{46}{B0}");
//onenoteApp.DeletePageContent(existingPageId, "{242BE490-7BF9-43D5-B719-}{50}{B0}");
#endregion
#endregion
7、搜索文件夹中的文件
#region 搜索文件夹中的文件: 17:12:57
//搜索文件夹中的文件
//时间: 14:54:44
//作者:白宁超
ArrayList GetAll(DirectoryInfo dir)
ArrayList FileList = new ArrayList();//定义数组存放图片文件名
FileInfo[] allFile = dir.GetFiles();
foreach (FileInfo fi in allFile)
FileList.Add(fi.Name);//遍历图片,并添加到数组
DirectoryInfo[] allDir = dir.GetDirectories();
foreach (DirectoryInfo d in allDir)
GetAll(d);
return FileL
catch (Exception e)
labMsg.Content = e.Message + "文件夹选择方式错误,重新选择!!";
return null;
#endregion
8、选择遍历文件夹图片
private void btn浏览_Click(object sender, RoutedEventArgs e)
txtmulu.Text = null;
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择待处理目录";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
string foldPath = dialog.SelectedP
txtfile.Text = foldP
DirectoryInfo d = new DirectoryInfo(@txtfile.Text);
ArrayList Flst = GetAll(d);
foreach (object o in Flst)
txtmulu.Text += "正在ORC图片: 【" + o.ToString() + "】\r\n";
labMsg.Content = "打开失败!!";
#region 上传单个图片
/*OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择一个本地图片";
ofd.Multiselect =
ofd.Filter = "支持的图片格式(*.jpg,*.jpeg,*.gif,*.bmp,*.png,*.tiff,*.emf)|*.*.*.*.*.*.*.emf";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
this.txt本地图片.Text = ofd.FileN
this.img图片.Source = new BitmapImage(new Uri(ofd.FileName, UriKind.RelativeOrAbsolute));
this.labMsg.Content = "本地图片已成功加载。";
#endregion
9、窗体关闭
private void Window_Closing(object sender, ponentModel.CancelEventArgs e)
DirectoryInfo dir = new DirectoryInfo(System.Configuration.ConfigurationManager.AppSettings["tmpPath"]);
foreach (FileInfo file in dir.GetFiles())
file.Delete();
【补充】orc前后结果对照:应部分园友建议,更为直观
整体orc结果:
具体orc结果:
【篇末】:程序中使用遍历文件,文件夹清空处理,文件的删除,文件的查找,文件夹的判空,重点在于图片的OneNote处理等操作,完成了批处理。可以自动执行批文件夹中图片,生成新的文本文件与图片名一致。现在不足之处,对文件夹的文件类型筛选为执行图片类型没有处理,容错不足,这个自己用文件放入纯图片可以,另外有时候进程处理不稳定,估计加入进度条原因。待版本2再做改进。下一节介绍文本文件处理入库(Oracle)。特别wpf中DataGrid的使用,如何在wpf中完成分页,简单的集合类型数据库分页可以,但是数据库连接如何分页?
阅读(...) 评论()}

我要回帖

更多关于 onenote2013破解版 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信