Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, August 27, 2019 10:56:01 AM(UTC)
ab-tools

Groups: Registered
Posts: 2


Hello,

while currently evaluating LeadTools I'm trying to accomplish a (I though ;-) ) pretty simple task, but apparently having some issues with that:
I have a bunch of RasterImages (acquired from a scanner, but could be any image, of course) that I would like to add as pages to a LEADDocument which should then be shown in a DocumentViewer.

I've tried to create a new page with "_documentViewer.Document.Pages.CreatePage" and then setting the page image with "documentPage.SetImage", but this seems not to work.

I would appreciate any idea on this pointing me to the right direction. :-)

Best regards and thanks in advance
Andreas
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, August 28, 2019 4:53:44 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Hello,

If you are looking to add a scanned image to an existing LEADDocument in the Document Viewer, you will need to create a virtual document of the LEADDocument to set the scanned image to, then add that virtual LEADDocument to the Document Viewer UI. You need to use the Document Factory, since if you just had a regular LEADDocument in the viewer it is not seen as virtual therefor you are unable to edit it (Add Pages, Delete Pages, etc.).

For your reference I have added a code snippet below that showcases this step.

Code:
// Global virtual document
LEADDocument virtualDocument;

CreateDocumentOptions cdo = new CreateDocumentOptions
  {
     Cache = cache,
     UseCache = true
  };

virtualDocument = DocumentFactory.Create(cdo);

After creating the new virtual LEADDocument you can create a new document page and add this to the virtual document. Then call the SetImage(e.Image) method inside the TwainAcquirePage Event. Should look similar to this:
      
private void TwainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e)
      {
         documentViewer.BeginUpdate();

         DocumentPage documentPage = virtualDocument.Pages.CreatePage(e.Image.ImageSize.ToLeadSizeD(), e.Image.XResolution);
         virtualDocument.Pages.Add(documentPage);
         documentPage.SetImage(e.Image.Clone());

         documentViewer.EndUpdate();
      }


Please let me know if you have any further questions. If you need a proof of concept application I would just need to know what type of application you are wanting to create (WPf, Winforms, etc.)

Thanks

Edited by moderator Monday, August 3, 2020 8:21:48 AM(UTC)  | Reason: Not specified

Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#3 Posted : Thursday, August 29, 2019 2:50:07 AM(UTC)
ab-tools

Groups: Registered
Posts: 2


Hello Matt,

first thanks a lot for your detailed reply!

So you are creating a new "LEADDocument" object and add the new page there.

I see you are calling "documentViewer.BeginUpdate()" and "documentViewer.EndUpdate()", but you never use "documentViewer.SetDocument()" to assign the new document to the document viewer:
So how does the document viewer know that the newly document should be displayed?

And another question:
If the document viewer display a document already and I just want to add an additional page from a RasterImage to this document, can I then directly use "documentViewer.Document.Pages.Add(...)" or do I always need to create a fresh new "LEADDocument" instance first?

I'm using WinForms by the way.

Best regards and again thanks for your detailed reply
Andreas
 
#4 Posted : Thursday, August 29, 2019 1:05:13 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Hello Andreas,

You will not have to create a new LEADDocument every time you want to edit the document. Just create a global virtual document as shown above. You can just set the document in the viewer as shown below.

Code:
// Global virtual document
LEADDocument virtualDocument;

CreateDocumentOptions cdo = new CreateDocumentOptions
  {
      Cache = cache,
      UseCache = true
  };

virtualDocument = DocumentFactory.Create(cdo);

OpenFileDialog ofd = new OpenFileDialog
  {
     InitialDirectory = @"C:\Users\Public\Documents\LEADTOOLS Images"
  };

if (ofd.ShowDialog() == true)
  {

      var options = new LoadDocumentOptions
          {
             UseCache = true,
             Cache = cache
          };
      LEADDocument document = DocumentFactory.LoadFromFile(ofd.FileName, options);

      virtualDocument.Pages.AddRange(document.Pages);
      SetDocument(virtualDocument);
  }


After you set the document you can then add pages like I showed in the code snippet in the above post with creating a new DocumentPage and using documentPage.SetImage(....). So instead of directly using "documentViewer.Document.Pages.Add(...)" create a new DocumentPage and add it to the global virtual document.

Code:
DocumentPage documentPage = virtualDocument.Pages.CreatePage(e.Image.ImageSize.ToLeadSizeD(), e.Image.XResolution);
virtualDocument.Pages.Add(documentPage);


Let me know if you have any further questions.

Thanks

Edited by user Friday, October 18, 2019 10:47:08 AM(UTC)  | Reason: Not specified

Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.062 seconds.