Sets the rendering engine to use when overlaying annotations during document conversion.
public void SetAnnRenderingEngineInstance(AnnRenderingEngine instance)
Public Sub SetAnnRenderingEngineInstance(ByVal instance As AnnRenderingEngine)
public:void SetAnnRenderingEngineInstance(AnnRenderingEngine^ instance)
public void setAnnRenderingEngineInstance(AnnRenderingEngine instance)
instance
The rendering engine to use when overlaying annotations during document conversion.
The AnnRenderingEngine instance passed to this method will be used when any job has the value of AnnotationsMode set to DocumentConverterAnnotationsMode.Overlay and raster conversion is used.
You must initialize this object with the IAnnObjectRenderer's to use before starting any conversion if annotation containers are to be overlayed on images.
AnnRenderingEngineInstance will return the same value passed for instance.
The previously set AnnRenderingEngineInstance is removed when a new instance is set. You can set a value of null.
This example will create an annotation file and use it as the overlay during raster PDF conversion.
using Leadtools;using Leadtools.Codecs;using Leadtools.Document.Writer;using Leadtools.Svg;using LeadtoolsExamples.Common;using Leadtools.Document;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;using Leadtools.Document.Converter;using Leadtools.Annotations.Rendering;public static void SetAnnRenderingEngineExample(){// Input document filestring inputDocumentFile = Path.Combine(ImagesPath.Path, "Leadtools.pdf");string inputAnnotationsFile = Path.Combine(ImagesPath.Path, "my-annotations.xml");string outputDocumentFile = Path.Combine(ImagesPath.Path, "my-output.pdf");// We will overlay the annotationsvar annotationsMode = DocumentConverterAnnotationsMode.Overlay;// Create the annotations file we will use for this sampleCreateTextAnnotations(DocumentFactory.RasterCodecsTemplate, inputDocumentFile, inputAnnotationsFile);// Convert the input file to a raster PDF with the annotations overlaidusing (var documentConverter = new DocumentConverter()){// If we run the example without the next line then we would get an error since we did not set a valid annotations rendering engine// This example will use the Windows Forms (GDI+) onedocumentConverter.SetAnnRenderingEngineInstance(new Leadtools.Annotations.Rendering.AnnWinFormsRenderingEngine());// Fill in the job data, passing the input file, input annotations file, output file,// format and annotations modevar jobData = new DocumentConverterJobData();jobData.InputDocumentFileName = inputDocumentFile;jobData.InputAnnotationsFileName = inputAnnotationsFile;jobData.OutputDocumentFileName = outputDocumentFile;jobData.RasterImageFormat = RasterImageFormat.RasPdfJpeg422;jobData.DocumentFormat = DocumentFormat.User;jobData.AnnotationsMode = annotationsMode;// Create a job and run itDocumentConverterJob job = documentConverter.Jobs.CreateJob(jobData);jobData.JobName = "conversion job";documentConverter.Jobs.RunJob(job);if (job.Status == DocumentConverterJobStatus.Success){Console.WriteLine("Success");}else{Console.WriteLine($"{job.Status} Errors");foreach (DocumentConverterJobError err in job.Errors){Console.WriteLine($" {err.Operation} at {err.InputDocumentPageNumber}: {err.Error.Message}");}}}}// Create an annotation file that contains a single text annotations for each page in the documentprivate static void CreateTextAnnotations(RasterCodecs rasterCodecs, string documentFile, string annotationsFile){if (File.Exists(annotationsFile))File.Delete(annotationsFile);var annCodecs = new AnnCodecs();// Get the size for each page, create a container for itint pageCount = rasterCodecs.GetTotalPages(documentFile);// The size of each annotations object we will add (1 by 0.5 inches)LeadSizeD annObjectSize = LeadSizeD.Create(720, 360);// The template for the AnnObject we will usevar annTextObjectTemplate = new AnnTextObject();annTextObjectTemplate.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("red"), LeadLengthD.Create(2));annTextObjectTemplate.HorizontalAlignment = AnnHorizontalAlignment.Center;annTextObjectTemplate.VerticalAlignment = AnnVerticalAlignment.Center;annTextObjectTemplate.Font = new AnnFont("Arial", 12);for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++){// Get the size of this page in pixels and convert to annotations unitsvar annContainer = new AnnContainer();using (CodecsImageInfo info = rasterCodecs.GetInformation(documentFile, false, pageNumber)){double resolution = Math.Max(info.XResolution, info.YResolution);if (resolution == 0)resolution = 96;annContainer.Mapper.MapResolutions(resolution, resolution, resolution, resolution);annContainer.Size = annContainer.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(info.ImageWidth, info.ImageHeight));}annContainer.PageNumber = pageNumber;// Add the text annotations object, 1 inch by half an inch, centered at the bottom of the page. Use the templatevar annTextObject = annTextObjectTemplate.Clone() as AnnTextObject;annTextObject.Rect = LeadRectD.Create((annContainer.Size.Width - annObjectSize.Width) / 2,annContainer.Size.Height - annObjectSize.Height,annObjectSize.Width,annObjectSize.Height);annTextObject.Text = "Page " + pageNumber.ToString();annContainer.Children.Add(annTextObject);// Save the container to the output fileannCodecs.Save(annotationsFile, annContainer, AnnFormat.Annotations, annContainer.PageNumber);}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Document.WriterImports Leadtools.SvgImports Leadtools.DocumentImports Leadtools.CachingImports Leadtools.Annotations.EngineImports Leadtools.OcrImports Leadtools.Document.ConverterImports LeadtoolsDocumentConverterExamples.LeadtoolsExamples.CommonPublic Shared Sub SetAnnRenderingEngineExample()' Input document fileDim inputDocumentFile As String = Path.Combine(ImagesPath.Path, "Leadtools.pdf")Dim inputAnnotationsFile As String = Path.Combine(ImagesPath.Path, "my-annotations.xml")Dim outputDocumentFile As String = Path.Combine(ImagesPath.Path, "my-output.pdf")' We will overlay the annotationsDim annotationsMode As DocumentConverterAnnotationsMode = DocumentConverterAnnotationsMode.Overlay' Create the annotations file we will use for this sampleCreateTextAnnotations(DocumentFactory.RasterCodecsTemplate, inputDocumentFile, inputAnnotationsFile)' Convert the input file to a raster PDF with the annotations overlaidUsing documentConverter As DocumentConverter = New DocumentConverter()' If we run the example without the next line then we would get an error since we did not set a valid annotations rendering engine' This example will use the Windows Forms (GDI+) onedocumentConverter.SetAnnRenderingEngineInstance(New Leadtools.Annotations.Rendering.AnnWinFormsRenderingEngine())' Fill in the job data, passing the input file, input annotations file, output file,' format and annotations modeDim jobData As New DocumentConverterJobData()jobData.InputDocumentFileName = inputDocumentFilejobData.InputAnnotationsFileName = inputAnnotationsFilejobData.OutputDocumentFileName = outputDocumentFilejobData.RasterImageFormat = RasterImageFormat.RasPdfJpeg422jobData.DocumentFormat = DocumentFormat.UserjobData.AnnotationsMode = annotationsMode' Create a job and run itDim job As DocumentConverterJob = documentConverter.Jobs.CreateJob(jobData)jobData.JobName = "conversion job"documentConverter.Jobs.RunJob(job)If job.Status = DocumentConverterJobStatus.Success ThenConsole.WriteLine("Success")ElseConsole.WriteLine($"{job.Status} Errors")For Each err As DocumentConverterJobError In job.ErrorsConsole.WriteLine($" {err.Operation} at {err.InputDocumentPageNumber}: {err.Error.Message}")NextEnd IfEnd UsingEnd Sub' Create an annotation file that contains a single text annotations for each page in the documentPrivate Shared Sub CreateTextAnnotations(rasterCodecs As RasterCodecs, documentFile As String, annotationsFile As String)If File.Exists(annotationsFile) ThenFile.Delete(annotationsFile)End IfDim annCodecs As New AnnCodecs()' Get the size for each page, create a container for itDim pageCount As Integer = rasterCodecs.GetTotalPages(documentFile)' The size of each annotations object we will add (1 by 0.5 inches)Dim annObjectSize As LeadSizeD = LeadSizeD.Create(720, 360)' The template for the AnnObject we will useDim annTextObjectTemplate As New AnnTextObject()annTextObjectTemplate.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("red"), LeadLengthD.Create(2))annTextObjectTemplate.HorizontalAlignment = AnnHorizontalAlignment.CenterannTextObjectTemplate.VerticalAlignment = AnnVerticalAlignment.CenterannTextObjectTemplate.Font = New AnnFont("Arial", 12)For pageNumber As Integer = 1 To pageCount' Get the size of this page in pixels And convert to annotations unitsDim annContainer As New AnnContainer()Using info As CodecsImageInfo = rasterCodecs.GetInformation(documentFile, False, pageNumber)Dim resolution As Double = Math.Max(info.XResolution, info.YResolution)If resolution = 0 Thenresolution = 96End IfannContainer.Mapper.MapResolutions(resolution, resolution, resolution, resolution)annContainer.Size = annContainer.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(info.ImageWidth, info.ImageHeight))End UsingannContainer.PageNumber = pageNumber' Add the text annotations object, 1 inch by half an inch, centered at the bottom of the page. Use the templateDim annTextObject As AnnTextObject = CType(annTextObjectTemplate.Clone(), AnnTextObject)annTextObject.Rect = LeadRectD.Create((annContainer.Size.Width - annObjectSize.Width) / 2,annContainer.Size.Height - annObjectSize.Height,annObjectSize.Width,annObjectSize.Height)annTextObject.Text = "Page " + pageNumber.ToString()annContainer.Children.Add(annTextObject)' Save the container to the output fileannCodecs.Save(annotationsFile, annContainer, AnnFormat.Annotations, annContainer.PageNumber)NextEnd Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
