←Select platform

EmptyPageMode Property

Summary

Determines how empty pages are treated during the conversion.

Syntax

C#
VB
Java
C++
public DocumentConverterEmptyPageMode EmptyPageMode { get; set; } 
Public Property EmptyPageMode() As DocumentConverterEmptyPageMode 
   Get 
   Set 
public:  
   property DocumentConverterEmptyPageMode^ EmptyPageMode 
   { 
      DocumentConverterEmptyPageMode^ get() 
      void set(DocumentConverterEmptyPageMode^ value) 
   } 
public DocumentConverterEmptyPageMode getEmptyPageMode() 
public void setEmptyPageMode(DocumentConverterEmptyPageMode value) 

Property Value

Determines how empty pages are treated during the conversion. Default value is DocumentConverterEmptyPageMode.None.

Remarks

This option controls how the document converter treats empty pages during the conversion as follows:

Value Description
DocumentConverterEmptyPageMode.None Do not do anything special. No detection is performed and empty pages will be added to the output document and the result is guaranteed to have the same number of pages as the input. This is the default behavior.
DocumentConverterEmptyPageMode.Skip Empty pages are skipped and not added to the final document. If the user instructs the converter to use the annotations during conversion, then any page that is empty but has an annotation container with objects is considered none-empty and is added to the output document.
DocumentConverterEmptyPageMode.SkipIgnoreAnnotations Similar to Empty with the annotations ignored. Empty pages are skipped even if they have annotations.

The document converter uses the following to detect if a page is empty:

  • If raster conversion is used, a BlankPageDetectorCommand image processing command with the options from DocumentConverterPreprocessor.BlankPageDetectorCommandFlags is run on the raster image to detect if the page is empty. The user can select other options that the default of BlankPageDetectorCommandFlags.None which only detects if the page is fully empty, for example, using margins and ignoring noise or bleed through.

  • If SVG conversion is used, the converter will enumerate all the elements in the page's SVG document object. The page is considered empty if it does not contain any elements besides the root <svg> element.

Example

This example creates a test document of four pages with the second page empty (all white). It will then use the document converter to generate an output document with and without skipping empty pages.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Documents; 
using Leadtools.Caching; 
using Leadtools.Annotations.Core; 
using Leadtools.Forms.Ocr; 
using Leadtools.Documents.Converters; 
 
public static void Run() 
{ 
   var inputDocumentFile = @"C:\Users\Public\Documents\LEADTOOLS Images\EmptyPageTestInput.tif"; 
   var outputDocumentFile1 = @"C:\Users\Public\Documents\LEADTOOLS Images\NoSkipping.tif"; 
   var outputDocumentFile2 = @"C:\Users\Public\Documents\LEADTOOLS Images\SkippingEmptyPages.tif"; 
 
   // Create a multi-page TIF file that is 4 pages with the second page empty 
   CreateTestDocumentFile(inputDocumentFile); 
 
   using (DocumentConverter documentConverter = new DocumentConverter()) 
   { 
      documentConverter.Diagnostics.EnableTrace = true; 
 
      // Make sure the options are set to not skip empty pages 
      documentConverter.Options.EmptyPageMode = DocumentConverterEmptyPageMode.None; 
 
      // Create a job to convert the input document to the first output file and run it 
      var jobData = DocumentConverterJobs.CreateJobData(inputDocumentFile, outputDocumentFile1, RasterImageFormat.CcittGroup4); 
      jobData.JobName = "No skipping empty pages"; 
      var job = documentConverter.Jobs.CreateJob(jobData); 
      documentConverter.Jobs.RunJob(job); 
 
      // Now, tell the document converter to skip empty pagess 
      documentConverter.Options.EmptyPageMode = DocumentConverterEmptyPageMode.SkipIgnoreAnnotations; 
      // And create a job to convert the input document to the second output file and run it 
      jobData = DocumentConverterJobs.CreateJobData(inputDocumentFile, outputDocumentFile2, RasterImageFormat.CcittGroup4); 
      jobData.JobName = "Skipping empty pages"; 
      job = documentConverter.Jobs.CreateJob(jobData); 
      documentConverter.Jobs.RunJob(job); 
 
      Console.WriteLine("Finished, checking the number of pages"); 
 
      // Show the number of pages in the first and second document, should report 4 and 3 
      using (var rasterCodecs = new RasterCodecs()) 
      { 
         var pageCount = rasterCodecs.GetTotalPages(outputDocumentFile1); 
         Console.WriteLine("First job did not skip any pages and produced {0} pages, should be 4", pageCount); 
         pageCount = rasterCodecs.GetTotalPages(outputDocumentFile2); 
         Console.WriteLine("Second job skipped the empty pages and produced {0} pages, should be 3", pageCount); 
      } 
   } 
} 
 
private static void CreateTestDocumentFile(string fileName) 
{ 
   var pageTemplateFile = @"C:\Users\Public\Documents\LEADTOOLS Images\Ocr{0}.tif"; 
 
   using (var rasterCodecs = new RasterCodecs()) 
   { 
      rasterCodecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
      CodecsSavePageMode savePageMode = CodecsSavePageMode.Overwrite; 
 
      for (var pageNumber = 1; pageNumber <= 4; pageNumber++) 
      { 
         if (pageNumber != 2) 
         { 
            using (var rasterImage = rasterCodecs.Load(string.Format(pageTemplateFile, pageNumber), 1)) 
            { 
               // Add it to the output document 
               rasterCodecs.Save(rasterImage, fileName, RasterImageFormat.CcittGroup4, 1, 1, 1, -1, savePageMode); 
               savePageMode = CodecsSavePageMode.Append; 
 
               if (pageNumber == 1) 
               { 
                  // Save an empty page (all white) the same size as the previous page 
                  using (var emptyPage = RasterImage.Create( 
                     rasterImage.Width, 
                     rasterImage.Height, 
                     rasterImage.BitsPerPixel, 
                     rasterImage.XResolution, 
                     RasterColor.FromKnownColor(RasterKnownColor.White))) 
                  { 
                     rasterCodecs.Save(emptyPage, fileName, RasterImageFormat.CcittGroup4, 1, 1, 1, -1, savePageMode); 
                  } 
               } 
            } 
         } 
      } 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.Svg 
Imports Leadtools.Documents 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Core 
Imports Leadtools.Forms.Ocr 
Imports Leadtools.Documents.Converters 
Imports LeadtoolsDocumentsConvertersExamples.LeadtoolsExamples.Common 
 
Public Shared Sub Run() 
   Dim inputDocumentFile As String = "C:\Users\Public\Documents\LEADTOOLS Images\EmptyPageTestInput.tif" 
   Dim outputDocumentFile1 As String = "C:\Users\Public\Documents\LEADTOOLS Images\NoSkipping.tif" 
   Dim outputDocumentFile2 As String = "C:\Users\Public\Documents\LEADTOOLS Images\SkippingEmptyPages.tif" 
 
   ' Create a multi-page TIF file that is 4 pages with the second page empty 
   CreateTestDocumentFile(inputDocumentFile) 
 
   Using documentConverter As New DocumentConverter() 
      documentConverter.Diagnostics.EnableTrace = True 
 
      ' Make sure the options are set to not skip empty pages 
      documentConverter.Options.EmptyPageMode = DocumentConverterEmptyPageMode.None 
 
      ' Create a job to convert the input document to the first output file and run it 
      Dim jobData As DocumentConverterJobData = DocumentConverterJobs.CreateJobData(inputDocumentFile, outputDocumentFile1, RasterImageFormat.CcittGroup4) 
      jobData.JobName = "No skipping empty pages" 
      Dim job As DocumentConverterJob = documentConverter.Jobs.CreateJob(jobData) 
      documentConverter.Jobs.RunJob(job) 
 
      ' Now, tell the document converter to skip empty pagess 
      documentConverter.Options.EmptyPageMode = DocumentConverterEmptyPageMode.SkipIgnoreAnnotations 
      ' And create a job to convert the input document to the second output file and run it 
      jobData = DocumentConverterJobs.CreateJobData(inputDocumentFile, outputDocumentFile2, RasterImageFormat.CcittGroup4) 
      jobData.JobName = "Skipping empty pages" 
      job = documentConverter.Jobs.CreateJob(jobData) 
      documentConverter.Jobs.RunJob(job) 
 
      Console.WriteLine("Finished, checking the number of pages") 
 
      ' Show the number of pages in the first and second document, should report 4 and 3 
      Using rasterCodecs As New RasterCodecs() 
         rasterCodecs.Options.RasterizeDocument.Load.Resolution = 300 
         Dim pageCount As Integer = rasterCodecs.GetTotalPages(outputDocumentFile1) 
         Console.WriteLine("First job did not skip any pages and produced {0} pages, should be 4", pageCount) 
         pageCount = rasterCodecs.GetTotalPages(outputDocumentFile2) 
         Console.WriteLine("Second job skipped the empty pages and produced {0} pages, should be 3", pageCount) 
      End Using 
   End Using 
End Sub 
 
Private Shared Sub CreateTestDocumentFile(fileName As String) 
   Dim pageTemplateFile As String = "C:\Users\Public\Documents\LEADTOOLS Images\Ocr{0}.tif" 
 
   Using rasterCodecs As New RasterCodecs() 
      rasterCodecs.Options.RasterizeDocument.Load.Resolution = 300 
 
      Dim savePageMode As CodecsSavePageMode = CodecsSavePageMode.Overwrite 
 
      For pageNumber As Integer = 1 To 4 
         If pageNumber <> 2 Then 
            Using rasterImage As RasterImage = rasterCodecs.Load(String.Format(pageTemplateFile, pageNumber), 1) 
               ' Add it to the output document 
               rasterCodecs.Save(rasterImage, fileName, RasterImageFormat.CcittGroup4, 1, 1, 1, -1, savePageMode) 
               savePageMode = CodecsSavePageMode.Append 
 
               If pageNumber = 1 Then 
                  ' Save an empty page (all white) the same size as the previous page 
                  Using emptyPage As RasterImage = rasterImage.Create( 
                     rasterImage.Width, 
                     rasterImage.Height, 
                     rasterImage.BitsPerPixel, 
                     rasterImage.XResolution, 
                     RasterColor.FromKnownColor(RasterKnownColor.White)) 
                     rasterCodecs.Save(emptyPage, fileName, RasterImageFormat.CcittGroup4, 1, 1, 1, -1, savePageMode) 
                  End Using 
               End If 
            End Using 
         End If 
      Next 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents.Converters Assembly