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, February 12, 2019 11:09:14 PM(UTC)
Vicki2018

Groups: Registered
Posts: 29

Thanks: 3 times

For the document HTML5 viewer, is there any function from the DocumentService that I can load the document from memory stream?
I can find lt.Document.DocumentFactory.loadFromUri or lt.Document.DocumentFactory.loadFromCache, but my source of document come from database, so I wonder if I can do it without saving the document to physical file.

Thanks.
 

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, February 13, 2019 9:42:11 AM(UTC)
Anthony Northrup

Groups: Registered, Tech Support, Administrators
Posts: 199

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

Hello Vicki,

Our HTML5 DocumentViewer will use a document ID for loading the pages of a PDF, which means you'll need to store it in the cache. Fortunately, you can take the MemoryStream and store it in the cache from within the Document Service using our .NET SDK. Below is an example of how to achieve this:
Code:

string LoadFromStream(Stream s)
{
   // Configure load options
   var cache = ServiceHelper.Cache;
   var loadOptions = new LoadDocumentOptions()
   {
      Cache = cache,
      CachePolicy = ServiceHelper.CreatePolicy(),
      UseCache = cache != null
   };

   // Load the document from your stream
   using (var document = DocumentFactory.LoadFromStream(s))
   {
      // Specific to Document Service
      CacheController.TrySetCacheUri(document);
      if (ServiceHelper.AutoUpdateHistory)
         document.History.AutoUpdate = true;
      ServiceHelper.SetRasterCodecsOptions(
         document.RasterCodecs, ServiceHelper.DefaultResolution
      );

      // Required
      document.AutoDeleteFromCache = false;
      document.AutoDisposeDocuments = true;
      document.AutoSaveToCache = false;
      document.SaveToCache();

      // Return the ID
      return document.DocumentId;
   }
}

Once you have performed the code above, return the documentID value to the client. They can then use this with the JavaScript DocumentFactory.loadFromCache method for viewing.

Please note: All references to the ServiceHelper class are referencing the Tools\Helpers\ServiceHelper.cs file within the DocumentService project. If you will be performing this code outside of that project, line 4 must be updated with valid cache. All other references (lines 8, and 15 through 21) can be removed.

Thanks,
Anthony Northrup
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
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.044 seconds.