MultiPage Scanning tweak...
Posted: Sat Jan 05, 2008 3:37 pm
YAY! I successfully got Open Dental to scan multiple pages into a pdf file and automatically import that file using TWAIN. This means the twain enabled fujitsu scanners will work with twain and do multiple pages at a time. This just shows how cool it is to have the source code to your software. I could name that ScanMultiPage anything... kinda neat. Not bad for a guy who doesnt know a thing about programming. I still have to test the Fujitsu next week at UCME4DK's office next week when I hook up his new Claris camera... But this is further then I have ever gotten on this before!
See the new icon on the Toolbar? MultiPageScan... Well the icon is the same but see the new description?

If you hit cancel, it will still try to import a pdf, so just hit cancel at the ItemInfo Window.
NOTE: EZTwain Pro is used which I believe is now free to anyone using OpenDental 5.4 and is on support (they are using a Binary version of Open Dental that was compiled by Open Dental)
Thanks to two people, one in Romania and the other in the UK and to Jordan for providing most the code!
http://www.codeguru.com/forum/showthread.php?t=442814
In the file ContrDocs.cs
http://www.koders.com/csharp/fid4D6F436 ... spx?s=zoom
The added code.
Line644
ToolBarMain.Buttons.Add(new ODToolBarButton(Lan.g(this, "ScanMultipage"), 5, Lan.g(this, "ImportPDF"), "ImportPDF"));
Line 993
case "ImportPDF":
OnImportPDF_Click();
break;
Line 1321
private void OnImportPDF_Click() {
File.Delete("C:\\image.pdf");
xImageDeviceManager.Obfuscator.ActivateEZTwain();
// Display TWAIN Select Source dialog
int wPIXTypes = EZTwain.SelectImageSource(this.Handle);
if (wPIXTypes == 0)
{//user clicked Cancel
return;
}
int j;
System.IntPtr hdib;
int N;
// Change this to your value:
N = 2;
EZTwain.SetHideUI(0);
EZTwain.SetJpegQuality(75);
if (EZTwain.OpenDefaultSource()==1)
{
EZTwain.SetResolution(100);
EZTwain.SetXferCount(N);
EZTwain.SetMultiTransfer(1);
if (EZTwain.BeginMultipageFile("c:\\image.pdf") == 0)
{
for (j = 1; j <= N; j++)
{
// If you can't get a Window handle, use IntPtr.Zero:
hdib = EZTwain.Acquire(this.Handle);
if (hdib == IntPtr.Zero)
{
break;
}
// <your image processing here>
EZTwain.DibWritePage(hdib);
EZTwain.DIB_Free(hdib);
}
EZTwain.EndMultipageFile();
}
EZTwain.CloseSource();
}
if (EZTwain.LastErrorCode() != 0)
{
EZTwain.ReportLastError("Unable to scan.");
}
OpenFileDialog openFileDialog=new OpenFileDialog();
openFileDialog.FileName = "c:\\image.pdf";
openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect=true;
string[] fileNames=openFileDialog.FileNames;
if(fileNames.Length<1){
return;
}
string nodeId="";
Document doc=null;
for(int i=0;i<fileNames.Length;i++){
bool copied = true;
try {
doc = imageStore.Import(fileNames, GetCurrentCategory());
}
catch(Exception ex) {
MessageBox.Show(Lan.g(this, "Unable to copy file, May be in use: ") + ex.Message + ": " + openFileDialog.FileName);
copied = false;
}
if(copied){
FillDocList(false);
SelectTreeNode(GetNodeById(MakeIdentifier(doc.DocNum.ToString(),"0")));
FormDocInfo FormD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(TreeDocuments.SelectedNode));
FormD.ShowDialog();//some of the fields might get changed, but not the filename
if(FormD.DialogResult!=DialogResult.OK){
DeleteSelection(false);
}else{
nodeId=MakeIdentifier(doc.DocNum.ToString(),"0");
}
}
}
See the new icon on the Toolbar? MultiPageScan... Well the icon is the same but see the new description?

If you hit cancel, it will still try to import a pdf, so just hit cancel at the ItemInfo Window.
NOTE: EZTwain Pro is used which I believe is now free to anyone using OpenDental 5.4 and is on support (they are using a Binary version of Open Dental that was compiled by Open Dental)
Thanks to two people, one in Romania and the other in the UK and to Jordan for providing most the code!
http://www.codeguru.com/forum/showthread.php?t=442814
In the file ContrDocs.cs
http://www.koders.com/csharp/fid4D6F436 ... spx?s=zoom
The added code.
Line644
ToolBarMain.Buttons.Add(new ODToolBarButton(Lan.g(this, "ScanMultipage"), 5, Lan.g(this, "ImportPDF"), "ImportPDF"));
Line 993
case "ImportPDF":
OnImportPDF_Click();
break;
Line 1321
private void OnImportPDF_Click() {
File.Delete("C:\\image.pdf");
xImageDeviceManager.Obfuscator.ActivateEZTwain();
// Display TWAIN Select Source dialog
int wPIXTypes = EZTwain.SelectImageSource(this.Handle);
if (wPIXTypes == 0)
{//user clicked Cancel
return;
}
int j;
System.IntPtr hdib;
int N;
// Change this to your value:
N = 2;
EZTwain.SetHideUI(0);
EZTwain.SetJpegQuality(75);
if (EZTwain.OpenDefaultSource()==1)
{
EZTwain.SetResolution(100);
EZTwain.SetXferCount(N);
EZTwain.SetMultiTransfer(1);
if (EZTwain.BeginMultipageFile("c:\\image.pdf") == 0)
{
for (j = 1; j <= N; j++)
{
// If you can't get a Window handle, use IntPtr.Zero:
hdib = EZTwain.Acquire(this.Handle);
if (hdib == IntPtr.Zero)
{
break;
}
// <your image processing here>
EZTwain.DibWritePage(hdib);
EZTwain.DIB_Free(hdib);
}
EZTwain.EndMultipageFile();
}
EZTwain.CloseSource();
}
if (EZTwain.LastErrorCode() != 0)
{
EZTwain.ReportLastError("Unable to scan.");
}
OpenFileDialog openFileDialog=new OpenFileDialog();
openFileDialog.FileName = "c:\\image.pdf";
openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect=true;
string[] fileNames=openFileDialog.FileNames;
if(fileNames.Length<1){
return;
}
string nodeId="";
Document doc=null;
for(int i=0;i<fileNames.Length;i++){
bool copied = true;
try {
doc = imageStore.Import(fileNames, GetCurrentCategory());
}
catch(Exception ex) {
MessageBox.Show(Lan.g(this, "Unable to copy file, May be in use: ") + ex.Message + ": " + openFileDialog.FileName);
copied = false;
}
if(copied){
FillDocList(false);
SelectTreeNode(GetNodeById(MakeIdentifier(doc.DocNum.ToString(),"0")));
FormDocInfo FormD=new FormDocInfo(PatCur,doc,GetCurrentFolderName(TreeDocuments.SelectedNode));
FormD.ShowDialog();//some of the fields might get changed, but not the filename
if(FormD.DialogResult!=DialogResult.OK){
DeleteSelection(false);
}else{
nodeId=MakeIdentifier(doc.DocNum.ToString(),"0");
}
}
}