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 : Thursday, May 21, 2020 2:45:16 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Dear Matt,

Can we load Annotations in a virtual document? I need to add annotations in the child document. so after loading the child document I'm loading respective annotation into the child document using below code,

Code:


var createOptions = new CreateDocumentOptions();
LEADDocument leadDocument = DocumentFactory.Create(createOptions);
leadDocument.AutoDisposeDocuments = true;
leadDocument.AutoDeleteFromCache = true;
leadDocument.Name = "Virtual Document";

LEADDocument childDocument = DocumentFactory.LoadFromFile($@"{docPath.Trim()}\{docfilename.Trim()}", new LoadDocumentOptions());

if (!string.IsNullOrEmpty(annotationEntity.Value))
{
         childDocument.IsReadOnly = false;
         var annCodecs = new AnnCodecs();
         AnnContainer[] annContainers = annCodecs.LoadAllFromString(annotationEntity.Value);
         childDocument.Annotations.SetAnnotations(annContainers);
}

leadDocument.Pages.AddRange(childDocument.Pages);


After adding the child document page to virtual document, the annotations are not rendering in document. Please can you assist?
 

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 : Friday, May 22, 2020 8:51:50 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Any hints on where I'm going wrong? The code compiles and works and annotations are loaded and no runtime errors but doesn't appear in the final document.
 
#3 Posted : Friday, May 22, 2020 9:02:04 AM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

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

Hello Abdul,

If you want to embed the annotations from an annotations XML file you will need to add a few things. First instead of using SetAnnotations(), you can use the AnnotationsUri property inside the LoadDocumentOptions class. See below code:

Code:

LoadDocumentOptions loadOptions = new LoadDocumentOptions();
var annotationsUri = new Uri(@"C:\Temp\annotations.xml");
loadOptions.AnnotationsUri = annotationsUri;
LEADDocument childDocument = DocumentFactory.LoadFromStream(ms, loadOptions);


Once you add that you are going to need to adjust the DocumentConverter part of you code to render the annotations onto the output document. You will need to add a DocumentWriter instance and an AnnRenderingEngine instance to the DocumentConverter. You will also need to set the AnnotationsMode property to embed the annotations. See code below:

Code:

leadDocument.Pages.Add(childDocument.Pages[0]);
DocumentConverter documentConverter = new DocumentConverter();
documentConverter.SetOcrEngineInstance(ocrEngine, false);
documentConverter.SetDocumentWriterInstance(new Leadtools.Document.Writer.DocumentWriter());
documentConverter.SetAnnRenderingEngineInstance(new AnnWinFormsRenderingEngine());
var jobData = new DocumentConverterJobData
{
     // If outputting to raster set to DocumentConverterAnnotationsMode.Overlay
     AnnotationsMode = DocumentConverterAnnotationsMode.Embed,
     Document = leadDocument,
     OutputDocumentStream = outputStream,
     DocumentFormat = Leadtools.Document.Writer.DocumentFormat.Pdf
};
var job = documentConverter.Jobs.CreateJob(jobData);
documentConverter.Jobs.RunJob(job);


Lastly, you will need to add the Leadtools.Pdf.Utilities.dll to your project. This dll cannot be added as a reference in Visual Studio, so you will need to get the dll from this folder: `C:\LEADTOOLS 20\Bin\Dotnet4\Win32`, and then copy the dll to your applications output directory.

If you have any questions about the above process please let me know.

Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#4 Posted : Friday, May 22, 2020 9:30:10 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Dear Matt,

Thanks for the assistance. I'll surely try that. Can I load the annotation from database instead of loading from file?

KR,
Abdul Rahman
 
#5 Posted : Friday, May 22, 2020 10:41:36 AM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

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

Hello Abdul,

To load the annotations file from database you can go one of two routes:

1) You can use the AnnotationsUri property, however you will need to save the stream to a temporary file and then pass that file in as a string to create the Uri.

2) You can use the SetAnnotations() method you were using previously and load the annotations file using the AnnCodecs class. This means you will load the AnnContainer[] array by passing in:
Code:

AnnContainer[] containers = codecs.LoadAll(stream);

Let me know if you have any questions about the above process. I have tested both options and they both output the same result.

Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#6 Posted : Wednesday, May 27, 2020 3:18:50 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Dear Matt,

what is the `ocrEngine` instance that I need to pass in this line of code?

Code:

documentConverter.SetOcrEngineInstance(ocrEngine, false);
documentConverter.SetAnnRenderingEngineInstance(new AnnWinFormsRenderingEngine());


And looks like `AnnWinFormsRenderingEngine` does not exists as Nuget. Where can I add this reference.

And as per your suggestion I'm not able to add `Leadtools.Pdf.Utilities.dll` in my asp.net core 3.1 web api project. When I add this dll I get the error as the reference is invalid or unsupported.

Please assist on what needs to be done.

Thanks,
Abdul Rahman
 
#7 Posted : Wednesday, May 27, 2020 1:05:16 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

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

Hello Abdul,

My apologies on adding the IOcrEngine in the code snippet I sent to you. When I was testing your use-case, I was using TIFF files to add to a a virtual document and exporting to PDF, which in this case requires a valid OCR Engine. If you are adding pages from a document and not from raster and exporting as document then you do not need to use the OCR Engine in your application (If you are and need more information on adding a valid OCR Engine, let me know).

I used the AnnWinFormsRenderingEngine since my test application used .NET Framework and not .NET Core like your application. For your use-case you will need to ensure you have the `Leadtools.Annotations.NETStandard` NuGet package installed and the line of code should look like this:

Code:

// .NET Core uses the AnnDrawRenderingEngine(), instead of AnnWinFormsRenderingEngine()
documentConverter.SetAnnRenderingEngineInstance(new AnnDrawRenderingEngine());


Lastly, for your use-case, since the `Leadtools.Pdf.Utilities.dll` is not a standard .NET assembly, you will need to tell the `LtPdf.dll` where the `LtPdfUtl.dll` is using the InitialPath property.
https://www.leadtools.co...options-initialpath.html

To do this add this code snippet to your .NET Core project:

Code:

// This can be disposed of after being set.
using (RasterCodecs codecs = new RasterCodecs())
{
      codecs.Options.Pdf.InitialPath = @"FILE PATH TO DIRECTORY WHERE LtPdfUtl.dll IS";
}


If you have any further questions please feel free to reach back out to us.

Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#8 Posted : Thursday, May 28, 2020 10:55:21 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Dear Matt,

That works but with only one issue. If I save the virtual file using DocumentWriter, the file is saved with annotations. But If I try to get the outputStream directly from the Virtual Document It fails. Any hint on why this fails?

Code:

RasterSupport.SetLicense(licenseFilePath, developerKey);
if (RasterSupport.KernelExpired)
{
    Console.WriteLine("LEADTOOLS License has Expired!\nPress [Enter] to exit.");
}

using (RasterCodecs codecs = new RasterCodecs())
{
    codecs.Options.Pdf.InitialPath = $@"{currentPath}\LeadTools CDLL";
}

var outputStream = new MemoryStream();
var createOptions = new CreateDocumentOptions();
LEADDocument leadDocument = DocumentFactory.Create(createOptions);
leadDocument.AutoDisposeDocuments = true;
leadDocument.AutoDeleteFromCache = true;
leadDocument.Name = "Virtual Document";

var docfilename = $@"{currentPath}\Print With Annotation\C000009.003";

LoadDocumentOptions loadOptions = new LoadDocumentOptions();
var annotationsUri = new Uri($@"{currentPath}\Print With Annotation\web.xml");
loadOptions.AnnotationsUri = annotationsUri;

LEADDocument childDocument = DocumentFactory.LoadFromFile(docfilename, loadOptions);
leadDocument.Pages.AddRange(childDocument.Pages);

// Finalized the new document
using (DocumentConverter documentConverter = new DocumentConverter())
{
    documentConverter.SetAnnRenderingEngineInstance(new AnnDrawRenderingEngine());
    documentConverter.SetDocumentWriterInstance(new DocumentWriter());
    var jobData = new DocumentConverterJobData
    {
        AnnotationsMode = DocumentConverterAnnotationsMode.Embed,
        Document = leadDocument,
        // This is the stream you want to send back to the browser
        OutputDocumentStream = outputStream,
        DocumentFormat = DocumentFormat.Pdf,
        //OutputDocumentFileName = $@"{currentPath}\Print With Annotation\test.pdf"
    };
    var job = documentConverter.Jobs.CreateJob(jobData);
    documentConverter.Jobs.RunJob(job);

    if (job.Errors.Count() > 0)
    {
        foreach (var error in job.Errors)
        {
            Console.WriteLine(error);
        }
    }
}


Thanks,
Abdul Rahman
 
#9 Posted : Thursday, May 28, 2020 2:14:03 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

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

Hello Abdul,

Yes, unfortunately you cannot gather the stream from a virtual document since the virtual document is not finalized. This means that the source pages from the child documents still only exist in the location the were originally loaded from. The virtual document only contains the information for where each page exists as well as other metadata about the page and file. To "finalize" the document you can either view the virtual document in the DocumentViewer or use the DocumentConverter. This creates a legitimate document that contains copies of the source pages in its own document structure.

Let me know if you have any questions about the above process.

Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#10 Posted : Thursday, May 28, 2020 2:19:32 PM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Alright that makes sense!! Thanks for the support..
 
#11 Posted : Monday, June 1, 2020 10:12:13 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Originally Posted by: Matthew Bresson Go to Quoted Post
Hello Abdul,

My apologies on adding the IOcrEngine in the code snippet I sent to you. When I was testing your use-case, I was using TIFF files to add to a a virtual document and exporting to PDF, which in this case requires a valid OCR Engine. If you are adding pages from a document and not from raster and exporting as document then you do not need to use the OCR Engine in your application (If you are and need more information on adding a valid OCR Engine, let me know).

I used the AnnWinFormsRenderingEngine since my test application used .NET Framework and not .NET Core like your application. For your use-case you will need to ensure you have the `Leadtools.Annotations.NETStandard` NuGet package installed and the line of code should look like this:

Code:

// .NET Core uses the AnnDrawRenderingEngine(), instead of AnnWinFormsRenderingEngine()
documentConverter.SetAnnRenderingEngineInstance(new AnnDrawRenderingEngine());


Lastly, for your use-case, since the `Leadtools.Pdf.Utilities.dll` is not a standard .NET assembly, you will need to tell the `LtPdf.dll` where the `LtPdfUtl.dll` is using the InitialPath property.
https://www.leadtools.co...options-initialpath.html

To do this add this code snippet to your .NET Core project:

Code:

// This can be disposed of after being set.
using (RasterCodecs codecs = new RasterCodecs())
{
      codecs.Options.Pdf.InitialPath = @"FILE PATH TO DIRECTORY WHERE LtPdfUtl.dll IS";
}


If you have any further questions please feel free to reach back out to us.

Thanks


Dear Matt,

Please can you assist me on how to set up Valid OCREngine Instance while converting document?

Thanks,
Abdul Rahman
 
#12 Posted : Monday, June 1, 2020 12:37:42 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

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

Hello Abdul,

To implement a valid OCR engine you will need to create the engine:

Code:

IOcrEngine ocrEngine;
// Create OCR engine
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false);

Then, startup the engine:
Code:

// Startup engine
ocrEngine.Startup(null, null, null, null);

Lastly, set the OCR engine instance to be used by the DcoumentConverter:
Code:

// Set OCR instance for DocumentConverter
documentConverter.SetOcrEngineInstance(ocrEngine, false);

// Ensure that you dispose of the IOcrEngine when finished
ocrEngine.Dispose();


Relevant documentation links:
https://www.leadtools.co...20/dh/fo/iocrengine.html
https://www.leadtools.co...anager-createengine.html
https://www.leadtools.co.../iocrengine-startup.html
https://www.leadtools.co...etocrengineinstance.html

If you have any further questions please feel free to reach back out to us.

Thanks,
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.300 seconds.