←Select platform

SetAnnRenderingEngineInstance Method


Sets the rendering engine to use when overlaying annotations during document conversion.

public void SetAnnRenderingEngineInstance( 
   AnnRenderingEngine instance 
   void SetAnnRenderingEngineInstance( 
      AnnRenderingEngine^ instance 
public void setAnnRenderingEngineInstance(AnnRenderingEngine instance) 
def SetAnnRenderingEngineInstance(self,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 file 
   string 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 annotations 
   var annotationsMode = DocumentConverterAnnotationsMode.Overlay; 
   // Create the annotations file we will use for this sample 
   CreateTextAnnotations(DocumentFactory.RasterCodecsTemplate, inputDocumentFile, inputAnnotationsFile); 
   // Convert the input file to a raster PDF with the annotations overlaid 
   using (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+) one 
      documentConverter.SetAnnRenderingEngineInstance(new Leadtools.Annotations.Rendering.AnnWinFormsRenderingEngine()); 
      // Fill in the job data, passing the input file, input annotations file, output file, 
      // format and annotations mode 
      var 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 it 
      DocumentConverterJob job = documentConverter.Jobs.CreateJob(jobData); 
      jobData.JobName = "conversion job"; 
      if (job.Status == DocumentConverterJobStatus.Success) 
         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 document 
private static void CreateTextAnnotations(RasterCodecs rasterCodecs, string documentFile, string annotationsFile) 
   if (File.Exists(annotationsFile)) 
   var annCodecs = new AnnCodecs(); 
   // Get the size for each page, create a container for it 
   int 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 use 
   var 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 units 
      var 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 template 
      var annTextObject = annTextObjectTemplate.Clone() as AnnTextObject; 
      annTextObject.Rect = LeadRectD.Create( 
         (annContainer.Size.Width - annObjectSize.Width) / 2, 
         annContainer.Size.Height - annObjectSize.Height, 
      annTextObject.Text = "Page " + pageNumber.ToString(); 
      // Save the container to the output file 
      annCodecs.Save(annotationsFile, annContainer, AnnFormat.Annotations, annContainer.PageNumber); 
import static org.junit.Assert.assertTrue; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.URI; 
import java.util.concurrent.Executors; 
import java.util.logging.ConsoleHandler; 
import java.util.logging.Handler; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import leadtools.*; 
import leadtools.annotations.rendering.AnnJavaRenderingEngine; 
import leadtools.caching.FileCache; 
import leadtools.codecs.*; 
import leadtools.document.DocumentFactory; 
import leadtools.document.DownloadDocumentOptions; 
import leadtools.document.LEADDocument; 
import leadtools.document.LoadDocumentOptions; 
import leadtools.document.LoadFromCacheOptions; 
import leadtools.document.UploadDocumentOptions; 
import leadtools.document.converter.DocumentConverter; 
import leadtools.document.converter.DocumentConverterEmptyPageMode; 
import leadtools.document.converter.DocumentConverterJob; 
import leadtools.document.converter.DocumentConverterJobData; 
import leadtools.document.converter.DocumentConverterJobError; 
import leadtools.document.converter.DocumentConverterJobErrorMode; 
import leadtools.document.converter.DocumentConverterJobStatus; 
import leadtools.document.converter.DocumentConverterJobs; 
import leadtools.document.writer.DocumentFormat; 
import leadtools.document.writer.DocumentWriter; 
import leadtools.ocr.OcrEngine; 
import leadtools.ocr.OcrEngineManager; 
import leadtools.ocr.OcrEngineType; 

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Converter Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.