LEADTOOLS Support
Document
Document SDK Questions
Receiving Error when attempting to add scanned pages to a virtual document
#1
Posted
:
Friday, March 19, 2021 11:37:52 AM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
Getting the following error when trying to add scanned image to a virtual document at line leadDocument.Pages.Add(scannedPage)
"Error Post-Operation in PagesAdded operation.
Object reference not set to an instance of an object.
On page 0."
DocumentPage scannedPage = leadDocument.Pages.CreatePage(LeadSizeD.Create(imageDPI * 8.5, imageDPI * 11), imageDPI) executes without error;
Using v20 Leadtools twain.dll. This code is part of a method:
private void twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e)
Do you have any idea what I am missing?
Code below.
createDocOptions = new CreateDocumentOptions();
createDocOptions.Cache = cache;
createDocOptions.UseCache = true;
createDocOptions.CachePolicy.SlidingExpiration = new TimeSpan(7, 0, 0, 0);
createDocOptions.DocumentId = strSequenceNo;
leadDocument = DocumentFactory.Create(createDocOptions);
//virtualDocument = DocumentFactory.Create(createDocOptions);
leadDocument.UserData = documentInfo;
//virtualDocument.UserData = documentInfo;
// Set in the viewer
documentViewer.BeginUpdate();
SetDocument(leadDocument);
//SetDocument(virtualDocument);
DocumentPage scannedPage = leadDocument.Pages.CreatePage(LeadSizeD.Create(imageDPI * 8.5, imageDPI * 11), imageDPI);
leadDocument.Pages.Add(scannedPage);
//DocumentPage scannedPage = virtualDocument.Pages.CreatePage(LeadSizeD.Create(imageDPI * 8.5, imageDPI * 11), imageDPI);
//virtualDocument.Pages.Add(scannedPage);
scannedPage.SetImage(e.Image.Clone());
documentViewer.EndUpdate();
#2
Posted
:
Tuesday, March 23, 2021 4:18:06 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Thank you for bringing this to our attention. Is this something we can reproduce locally using a virtual scanner?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Tuesday, March 23, 2021 4:46:11 PM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
I hope so.
The code I sent is the essential part of my private void twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e) method.
This is for an older twain 32 bit bulk scanner (i.e. 50 or more sheets of documents) that has no updated 64 bit drivers available.
You should be able to test the code with a basic twain scanner demo.
Whenever I try to run one of your demos I get an "Unrecognized MSG DG DAT combination.
I had to initialize my scanner by calling
#region Get Scanner Documents Code
private void InitializeScanner()
{
try
{
isScannerConnected = false;
RasterCodecs = new RasterCodecs();
RasterCodecs.Options.Load.AllPages = true;
RasterCodecs.Options.RasterizeDocument.Load.XResolution = imageDPI;
RasterCodecs.Options.RasterizeDocument.Load.YResolution = imageDPI;
string winLogin = Environment.UserName.ToLower();
blUser = new User(winLogin, Settings.Default.DataBaseVersion);
//logFilename = ImageManagementSystem.Properties.Settings.Default.LogPath + DateTime.Now.ToString("yyyyMMdd") + "_" + blUser.OperatorID + ".log";
try
{
twainSession = new TwainSession();
TwainVersion twainVersion = TwainVersion.Version1; // Force use of the 32 bit twain driver.
TwainSession.SetVersion(twainVersion);
try
{
twainSession.Startup(IntPtr.Zero, "Canon", "Canon Scanner", "Version 1.0"
, "Image Management System", TwainStartupFlags.None);
//twainSession.Startup2(IntPtr.Zero, "Canon", "Canon Scanner", "Version 1.0"
// , "Image Management System", TwainStartupFlags.None, TwainLanguage.LanguageEnglish, TwainCountry.CountryUsa);
if (twainSession.SelectSource(string.Empty) != DialogResult.OK)
MessageBox.Show("Error Selecting Source");
twainSession.AcquirePage += twainSession_AcquirePage;
isScannerConnected = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#4
Posted
:
Wednesday, March 24, 2021 4:53:29 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
What value are you using for "imageDPI "?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#5
Posted
:
Wednesday, March 24, 2021 4:54:50 PM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
#6
Posted
:
Thursday, March 25, 2021 4:29:45 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Thank you. Could you include the entire stack trace and exception message? I'm attempting to reproduce this locally.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#7
Posted
:
Monday, April 5, 2021 11:04:54 AM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
I thought I replied to this immediately, but I do not see it at this time.
Please forgive me if this is a duplicate.
The error happens at this line of code.
There is not a per se exception message
private void documentViewer_Operation(object sender, DocumentViewerOperationEventArgs e)
{
void Updater(DocumentViewerOperationEventArgs args)
{
// If we have an error, show it
if (args.Error != null)
{
====> var message = $"Error {(args.IsPostOperation ? "Post-Operation" : "Pre-Operation")} in {args.Operation} operation. \n" +
$"{args.Error.Message} \nOn page {args.PageNumber}.";
MessageBox.Show(message, "Render Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
The Stack trace is below:
ImageManagementSystem.exe!ImageManagementSystem.frmRedact.documentViewer_Operation.__Updater|0(Leadtools.Document.Viewer.DocumentViewerOperationEventArgs args) Line 842
at D:\Projects\Imaging Dept Projects\Image Management System\Image Management System\frmRedact.cs(842)
ImageManagementSystem.exe!ImageManagementSystem.frmRedact.documentViewer_Operation(object sender, Leadtools.Document.Viewer.DocumentViewerOperationEventArgs e) Line 948
at D:\Projects\Imaging Dept Projects\Image Management System\Image Management System\frmRedact.cs(948)
[External Code]
ImageManagementSystem.exe!ImageManagementSystem.frmRedact.twainSession_AcquirePage(object sender, Leadtools.Twain.TwainAcquirePageEventArgs e) Line 4331
at D:\Projects\Imaging Dept Projects\Image Management System\Image Management System\frmRedact.cs(4331)
[External Code]
ImageManagementSystem.exe!ImageManagementSystem.frmRedact.ScanDocuments() Line 4494
at D:\Projects\Imaging Dept Projects\Image Management System\Image Management System\frmRedact.cs(4494)
ImageManagementSystem.exe!ImageManagementSystem.frmRedact.ScanEvent() Line 4460
at D:\Projects\Imaging Dept Projects\Image Management System\Image Management System\frmRedact.cs(4460)
#8
Posted
:
Wednesday, April 7, 2021 2:44:57 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
I've reached out to you via email regarding this.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#9
Posted
:
Wednesday, April 7, 2021 4:35:25 PM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
Thank you Nick,
I downloaded the libraries new (version 20.0.4.0) as recommended.
In the process of updating all the Leadtools libraries, I did find a couple of Leadtools references that were pointing at version 19 libraries.
I corrected all those libraries, but I am still receiving the same error in the documentViewer_Operation event handler in the Updater method
#10
Posted
:
Thursday, April 8, 2021 4:14:11 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Alright--if the issue is persisting when ensuring the application is using the latest versions of the v20 libraries, it'll be necessary to reproduce this in-house to diagnose farther. How large is your application?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#11
Posted
:
Thursday, April 8, 2021 5:48:46 PM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
It's pretty large and it uses third party controls other than Leadtools.
However, I created a simplified version of the application to send to you back in May of last year.
Let me see if I can create a simplified version of the current state of the code.
#12
Posted
:
Monday, April 12, 2021 12:12:15 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
I've reached out to you via email with upload information--please let me know here or via return email when you've uploaded the sample version and what the filename is.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#13
Posted
:
Monday, April 12, 2021 12:49:11 PM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
I have replied to your email with the filename that I uploaded.
Thank you.
#14
Posted
:
Tuesday, April 13, 2021 4:18:27 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Thank you for your patience. I've determined this occurs when using a software-based scanner as well and as such the document you included wasn't used. (In modifying the program to run locally, I found and disabled the barcode check.)
Could you move the call to SetDocument(LEADDocument) to occur after the leadDocument.Pages.Add(scannedPage) line?
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#15
Posted
:
Tuesday, April 13, 2021 4:54:23 PM(UTC)
Groups: Registered
Posts: 52
Thanks: 14 times
Thank you.
That seems to have fixed the error below:
"Error Post-Operation in PagesAdded operation.
Object reference not set to an instance of an object.
On page 0."
I have some other clean up issues to do as far as setting the pages read by the scanner for a given Document, but I think I can handle them from here.
#16
Posted
:
Thursday, April 15, 2021 7:50:03 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Glad this resolves the issue--I'll close out this case now.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Questions
Receiving Error when attempting to add scanned pages to a virtual document
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.