LEADTOOLS Support
Document
Document SDK Questions
can I load document from memorystream to document viewer?
#1
Posted
:
Tuesday, February 12, 2019 11:09:14 PM(UTC)
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.
#2
Posted
:
Wednesday, February 13, 2019 9:42:11 AM(UTC)
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.
LEADTOOLS Support
Document
Document SDK Questions
can I load document from memorystream to document viewer?
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.