←Select platform

AllPages Property

Summary
Gets or sets a value that indicates whether to clone all the pages if the source image is multipage.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public bool AllPages { get; set; } 
@property (nonatomic, assign) BOOL allPages 
public final boolean getAllPages() 
public final void setAllPages(boolean value) 
public: 
property bool AllPages { 
   bool get(); 
   void set (    bool ); 
} 
AllPages # get and set (CloneCommand) 

Property Value

true to clone all the pages if the source image is multipage; false, otherwise.

Remarks

If the source image (the image passed to the RasterCommand.Run method) contains multiple pages, then you can use the AllPages property to control whether the CloneCommand will create a copy of the current active page or all the pages in the image.

Note that when the source image has multiple pages and the value of AllPages was set to true, then the RasterCommand.Progress event will fire from 0 to 100 for each page processed. If an overall progress percentage is desired, then you can inspect the RasterImage.Page and RasterImage.PageCount properties of the SourceImage property to calculate this value as shown in the example below.

The default value of this property is false to clone only the current page.

Example

This example will clone a multipage image and shows the over-all progress value.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
 
 
private void CloneAllTest() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
 
	// Create a multi-page image for testing purposes 
	RasterImage image = null; 
	for (int i = 1; i <= 4; i++) 
	{ 
		RasterImage pageImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "OCR" + i.ToString() + ".tif")); 
		if (image == null) 
			image = pageImage; 
		else 
		{ 
			image.AddPage(pageImage); 
			pageImage.Dispose(); 
		} 
	} 
 
	Console.WriteLine("Input image has {0} pages", image.PageCount); 
 
	// Clone all pages 
	CloneCommand cloneCmd = new CloneCommand(); 
	cloneCmd.AllPages = true; 
	cloneCmd.Progress += new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); 
	cloneCmd.Run(image); 
	cloneCmd.Progress -= new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); 
 
	RasterImage destinationImage = cloneCmd.DestinationImage; 
	Console.WriteLine("Cloned image has {0} pages", destinationImage.PageCount); 
 
	destinationImage.Dispose(); 
	image.Dispose(); 
	codecs.Dispose(); 
} 
 
private void cloneCmd_Progress(object sender, RasterCommandProgressEventArgs e) 
{ 
	// By using the SourceImage property of the CloneCommand we can find out 
	// the progress for the current page as well as the overall 
	CloneCommand cmd = sender as CloneCommand; 
 
	int overallPercent; 
 
	if (cmd.AllPages && cmd.SourceImage.PageCount > 1) 
	{ 
		// For multiple-pages, the command will fire the Progress event from 0 to 100 for each page 
		// Use the source image Page property to find out where we are in overall completetion 
		overallPercent = ((cmd.SourceImage.Page - 1) * 100 + e.Percent) / cmd.SourceImage.PageCount; 
	} 
	else 
	{ 
		// Otherwise, the percent is the same as the current page 
		overallPercent = e.Percent; 
	} 
 
	Console.WriteLine("Current page completion: {0} of {1} - {2}% - Overall image completion {3}%", cmd.SourceImage.Page, cmd.SourceImage.PageCount, e.Percent, overallPercent); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.*; 
 
 
public void cloneAllPagesCommandExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   // Create a multi-page image for testing purposes 
   RasterImage image = null; 
   for (int i = 1; i <= 3; i++) { 
      RasterImage pageImage = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "ocr" + i + ".tif")); 
      if (image == null) 
         image = pageImage; 
      else { 
         image.addPage(pageImage); 
         pageImage.dispose(); 
      } 
      codecs.save(pageImage, combine(LEAD_VARS_IMAGES_DIR, "ocr" + i + ".tif"), RasterImageFormat.TIF, 0); 
 
      assertTrue("file unsuccessfully saved to " + combine(LEAD_VARS_IMAGES_DIR, "ocr" + i + ".tif"), 
            (new File(combine(LEAD_VARS_IMAGES_DIR, "ocr" + i + ".tif"))).exists()); 
      System.out.printf("File saved successfully to %s%n", combine(LEAD_VARS_IMAGES_DIR, "ocr" + i + ".tif")); 
   } 
 
   System.out.printf("Input image has %s pages%n", image.getPageCount()); 
 
   // Clone all pages 
   CloneCommand cloneCmd = new CloneCommand(); 
   cloneCmd.setAllPages(true); 
   cloneCmd.addProgressListener(cloneCmd_Progress); 
   cloneCmd.run(image); 
   cloneCmd.removeProgressListener(cloneCmd_Progress); 
 
   RasterImage destinationImage = cloneCmd.getDestinationImage(); 
   codecs.save(destinationImage, combine(LEAD_VARS_IMAGES_DIR, "Result.tif"), RasterImageFormat.TIF, 0); 
 
   assertTrue("file unsuccessfully saved to " + combine(LEAD_VARS_IMAGES_DIR, "Result.tif"), 
         (new File(combine(LEAD_VARS_IMAGES_DIR, "Result.tif"))).exists()); 
   System.out.printf("File saved successfully to %s%n", combine(LEAD_VARS_IMAGES_DIR, "Result.tif")); 
 
   System.out.printf("Cloned image has %s pages%n", destinationImage.getPageCount()); 
 
   destinationImage.dispose(); 
   image.dispose(); 
   codecs.dispose(); 
} 
 
RasterImageProgressListener cloneCmd_Progress = new RasterImageProgressListener() { 
 
   @Override 
   public void RasterImageProgressAlert(RasterImageProgressEvent e) { 
      // By using the SourceImage property of the CloneCommand we can find out 
      // the progress for the current page as well as the overall 
      CloneCommand cmd = (CloneCommand) e.getSource(); 
 
      int overallPercent; 
 
      if (cmd.getAllPages() && cmd.getSourceImage().getPageCount() > 1) { 
         // For multiple-pages, the command will fire the Progress event from 0 to 100 
         // for each page 
         // Use the source image Page property to find out where we are in overall 
         // completetion 
         overallPercent = ((cmd.getSourceImage().getPage() - 1) * 100 + e.getPercentComplete()) 
               / cmd.getSourceImage().getPageCount(); 
      } else { 
         // Otherwise, the percent is the same as the current page 
         overallPercent = e.getPercentComplete(); 
      } 
 
      System.out.printf("Current page completion: %1s of %2s - %3s% - Overall image completion %4s%%n", 
            cmd.getSourceImage().getPage(), cmd.getSourceImage().getPageCount(), e.getPercentComplete(), 
            overallPercent); 
   } 
}; 
Requirements

Target Platforms

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

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