MultiPage Scanning tweak...

For complex topics that regular users would not be interested in. For power users and database administrators.
Post Reply
User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

MultiPage Scanning tweak...

Post by Justin Shafer » 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! :D


See the new icon on the Toolbar? MultiPageScan... Well the icon is the same but see the new description?
Image

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! :D
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");
}
}
}
Last edited by Justin Shafer on Sat Jan 05, 2008 4:51 pm, edited 1 time in total.

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Post by jordansparks » Sat Jan 05, 2008 4:28 pm

Nicely done. There are a number of improvements that I can see that would need to be made before adding it. I can quickly make them, but then I don't have any way to test. I think what I will do is add part of this changes to 5.6, make the edits that I have in mind, and then post the new version here. You can take mine and paste it into what you have running to test it one more time.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

Post by Justin Shafer » Sat Jan 05, 2008 4:37 pm

Thanks! I will do anything you need me to do. I can either add your code into mine after a fresh download from svn... or I can wait on the 5.6...
I just know that I will be going to hook up the claris most likely tuesday... I can test it pretty easily just by asking an employee to load the scanner with paper remotely.. thats the office that was using dentrix and the fi-5110. http://www.youtube.com/watch?v=WwuesstIT8A
They have two scanners I think, so maybe I could ask to bring one home... It may be another office that has two snapscan's though...
Let me know what I need to do. :)

By the way in EZ Twain I told it I needed code to acquire images from a any twain device and then made it multipage. The FEEDER option may need to be called but the only way to really know is wait and test...

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Post by jordansparks » Sat Jan 05, 2008 5:07 pm

Here are the minor changes. Are you able to easily test it to see if it still works?

Code: Select all

		private void OnImportPDF_Click() { 
			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;
			N = 2; // Change this to your value
			EZTwain.SetHideUI(0); 
			EZTwain.SetJpegQuality(75); 
			string filename=Path.GetTempFileName();
			if (EZTwain.OpenDefaultSource()==1){ 
				EZTwain.SetResolution(100); 
				EZTwain.SetXferCount(N); //js: I don't know what this is
				EZTwain.SetMultiTransfer(1); 
				if (EZTwain.BeginMultipageFile(filename) == 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."); 
			} 
			string nodeId=""; 
			Document doc=null; 
			try { 
				doc = imageStore.Import(filename, GetCurrentCategory()); 
			} 
			catch(Exception ex) { 
				MessageBox.Show(Lan.g(this, "Unable to copy file, May be in use: ") + ex.Message + ": " + filename); 
				return;
			} 
			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"); 
			} 
			//Reselect the last successfully added node when necessary.
			if(doc!=null && MakeIdentifier(doc.DocNum.ToString(),"0")!=nodeId) {
				SelectTreeNode(GetNodeById(MakeIdentifier(doc.DocNum.ToString(),"0")));
			}
			FillDocList(true);
		}
Jordan Sparks, DMD
http://www.opendental.com

User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

Post by Justin Shafer » Sat Jan 05, 2008 5:34 pm

Yes I can... I went out for awhile... I will test it out when I get back. Cool... Had to show a buddy of mine...

enamelrod
Posts: 462
Joined: Tue Jul 24, 2007 9:51 am

Re: MultiPage Scanning tweak...

Post by enamelrod » Sat May 30, 2009 8:41 pm

was this ever completed? for multipage scanning?

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: MultiPage Scanning tweak...

Post by jordansparks » Mon Jun 01, 2009 10:59 am

The code is obviously mostly there. But we can't just drop it in. It's going to take some work.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
Hersheydmd
Posts: 700
Joined: Sun May 03, 2009 9:12 pm

Re: MultiPage Scanning tweak...

Post by Hersheydmd » Fri Jun 12, 2009 2:34 am

I found this thread from 2007 and I am wondering whatever happened with this? Did it ever work out? I want to shred my paper charts after scanning them into the opendental images folder. Saving them as individual single page .jpeg's is not a realistic option. Multipage .pdf's would make much more sense.
Robert M Hersh DMD, FAGD
Univ. of Penn 1982
Brooklyn, NY 11234
https://www.facebook.com/pages/Robert-M ... 1471599429

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: MultiPage Scanning tweak...

Post by jordansparks » Fri Jun 12, 2009 6:04 am

It's totally a time issue for us. I'm right in the middle of a huge complicated overhaul of the insurance benefit calculations. I've been staring at thousands of lines of math for weeks. One thing has to get finished before moving on to the next. And when deciding what to do next, it will largely be determined by the votes in the feature request system.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

Re: MultiPage Scanning tweak...

Post by Justin Shafer » Sun Oct 18, 2009 10:13 am

I need to test this code out... I am buying a new all in one soon.. My scanner broke awhile back and I have just been using the neighbors if I need to scan which I do probably once a year...

User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

Re: MultiPage Scanning tweak...

Post by Justin Shafer » Sun Oct 18, 2009 10:45 am

I did some reading in the eztwain manual and it says that most webcams will bomb if they have the resolution set in the twain commands.... Here are the commands from the wizard for webcam, single image import only... If I had a webcam I could test this better... or an IOC....

System.IntPtr hdib;
EZTwain.SetHideUI(false);
if (EZTwain.OpenDefaultSource()) {
EZTwain.SetXferCount(1);
// If you can't get a Window handle, use IntPtr.Zero:
hdib = EZTwain.Acquire(this.Handle);
if (hdib!=IntPtr.Zero) {
// <your image processing here>
EZTwain.DIB_Free(hdib);
}
}
if (EZTwain.LastErrorCode()!=0) {
EZTwain.ReportLastError("Unable to scan.");
}

User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

Re: MultiPage Scanning tweak...

Post by Justin Shafer » Sun Oct 18, 2009 10:47 am

Perhaps the dialog to choose the device would help...

// Display TWAIN Select Source dialog
EZTwain.SelectImageSource(IntPtr.Zero);

User avatar
Justin Shafer
Posts: 596
Joined: Sat Jul 28, 2007 7:34 pm
Location: Fort Worth, TX.

Re: MultiPage Scanning tweak...

Post by Justin Shafer » Sun Dec 20, 2009 5:15 am

I still havent bought that scanner. I should break down and buy one but I go to so many dental offices that have and I rarely need to use a scanner. Anyways... That code did work at that one office... But I never tried the modified code. I would like to test this more, as I am willing to bet eztwain could be with us for awhile? Stay away from Vintasoft... :lol: At least thats been my experience so far. The hard part is finding a library that works well with the majority of scanners. As I know a PMS that recently switched scannning libraries and now some offices really need to buy new scanners for it to work reliably without rebooting something.

Can I still try that code if I wanted to.. The modified one.. I guess I can try and find out. Just for fun. After I get my imaginary scanner. Would like to buy an FI-5110C, but I dont really need it.. But I could test it with an office nearby. Probably get a brother of an hp....

It looks like you guys switched to Ez-Twain Pro instead of Classic so that is cool...

Jay
Posts: 272
Joined: Fri Aug 06, 2010 10:01 am

Re: MultiPage Scanning tweak...

Post by Jay » Fri Aug 13, 2010 5:35 am

I know this is an old thread but is multipage scanning now officially supported or must one apply the tweak. If tweaking is still needed can some kind soul publish the latest version of the tweak and a brief how-to? Also could someone confirm that the tweak works and is stable with the Epson WorkForce Pro GT-S50? I ask because the office loves the Fujitsu S1500 and needs a second one. But in light of this tweak (feature?) Epson might be the way to go.

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: MultiPage Scanning tweak...

Post by jordansparks » Fri Aug 13, 2010 12:46 pm

This is an ordinary feature request that we have not yet implemented. Nobody is going to take the time to "tweak" anything.
Jordan Sparks, DMD
http://www.opendental.com

Post Reply