←Select platform

DeletePage(Stream,int) Method

Summary
Deletes the specified page from a multipage file in a stream, if the format supports delete operations.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void DeletePage( 
   Stream stream, 
   int pageNumber 
) 
- (BOOL)deletePageInStream:(LTLeadStream *)stream page:(NSInteger)page error:(NSError **)error 
public void deletePage(ILeadStream stream, int page) 
public: 
void DeletePage(  
   Stream^ stream, 
   int pageNumber 
)  
def DeletePage(self,stream,pageNumber): 

Parameters

stream
A Stream containing the data of the image file from which to delete the page.

pageNumber
1-based index of the page to delete. Use -1 to delete the last page. Use 1 to delete the first page.

Remarks

The following file formats support delete operations:

  • TIFF (most TIFF formats, including JTIF, but excluding EXIF)
  • PCX
  • Winfax
Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void SaveFile2Example() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_SaveFile2.tif"); 
 
   // Use GDI+ to create a RasterImage with 4 pages containing text showing the page number 
   RasterImage image = null; 
   const int pageCount = 4; 
 
   using (System.Drawing.Font f = new System.Drawing.Font("Arial", 36, System.Drawing.FontStyle.Bold)) 
   using (System.Drawing.Bitmap btmp = new System.Drawing.Bitmap(320, 200)) 
   using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat()) 
   { 
      System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, btmp.Width, btmp.Height); 
      sf.Alignment = System.Drawing.StringAlignment.Center; 
      sf.LineAlignment = System.Drawing.StringAlignment.Center; 
 
      for (int i = 1; i <= pageCount; i++) 
      { 
         // Create a GDI+ bitmap with the text 
         string text = "Page " + i; 
 
         using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(btmp)) 
         { 
            g.FillRectangle(System.Drawing.Brushes.White, rc); 
            g.DrawString(text, f, System.Drawing.Brushes.Black, rc, sf); 
         } 
 
         RasterImage tempImage = Leadtools.Drawing.RasterImageConverter.ConvertFromImage(btmp, Leadtools.Drawing.ConvertFromImageOptions.None); 
 
         if (image == null) 
            image = tempImage; 
         else 
            image.AddPage(tempImage); 
      } 
   } 
 
   // Save all the pages to the file 
   // The file should have 4 pages now: 1, 2, 3, 4 
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, pageCount, 1, CodecsSavePageMode.Overwrite); 
   image.Dispose(); 
 
   // Load the 3rd page and insert it as the second 
   // The file should have 5 pages now: 1, 3, 2, 3, 4 
   image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 3, 3); 
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 2, CodecsSavePageMode.Insert); 
   image.Dispose(); 
 
   // Load the last page, and insert it as the first 
   // The file should have 5 pages now: 4, 1, 3, 2, 3, 4 
   image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 5, 5); 
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert); 
   image.Dispose(); 
 
   // Replace the 5th page with the 2nd 
   // The file should have 5 pages now: 4, 1, 3, 2, 1, 4 
   image = codecs.Load(destFileName, 0, CodecsLoadByteOrder.BgrOrGray, 2, 2); 
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, 1, 5, CodecsSavePageMode.Replace); 
   image.Dispose(); 
 
   // Delete the 2nd and 6th pages 
   // The file should have 5 pages now: 4, 3, 2, 1 
   codecs.DeletePage(destFileName, 2); 
   // Notice, -1 because we already deleted a page, so 6th page is now 5th 
   codecs.DeletePage(destFileName, 6 - 1); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

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.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.